2009-06-04 7 views
11

पर डब्ल्यूसीएफ का उपयोग करके वेब सेवा को कॉल करना हमारी परियोजना में हमारे पास एक जावा वेब सेवा है जो http और https पर चलती है। हम अपने वेब ऐप के बाहरी संस्करण के लिए आंतरिक रूप से और https का उपयोग करना चाहते हैं।एचटीपी और एचटीपीएस

इसलिए हमने अपने आवेदन में प्रॉक्सी क्लास बनाया है और हमने वेब/app.config में http के लिए बाइंडिंग सेट की है और सभी ठीक काम करता है।

कोड और कॉन्फ़िगरेशन को हमारे बाहरी एप्लिकेशन में उसी सेवा के लिए https का समर्थन करने के लिए हमें किन परिवर्तनों की आवश्यकता होगी? यदि संभव हो तो कृपया व्याख्या करने के लिए कोड स्निपेट की आपूर्ति करें!

उत्तर

0

कृपया Configuring HTTP and HTTPS देखें:

Using Windows Communication Foundation (WCF) over HTTP either requires the use of a host, such as Internet Information Services (IIS), or manual configuration of the HTTP settings through the HTTP Server API. This document describes manually configuring WCF when using HTTP and HTTPS.

और यह भी WCF Bindings Needed For HTTPS देखें:

I just finished writing my first production WCF application, which worked very well until I deployed it to our production environment. All of a sudden none of the WCF calls would work, and I would get a JavaScript "TestService is not defined" error. When I look inside the JS service reference (in debug mode), I got the following error:

Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding. Registered base address schemes are [https]

So apparently my WCF service registered itself as HTTPS (since it is over SSL), but my binding was only configured for HTTP. The solution is to define a custom binding inside your Web.Config file and set the security mode to "Transport". Then you just need to use the bindingConfiguration property inside your endpoint definition to point to your custom binding. The entire HTTPS-enabled system.serviceModel section is below:

0

मैं समझता हूँ कि आप WCF का उपयोग कर रहे ग्राहक, एक दूरस्थ वेब सेवा से कनेक्ट होता है HTTPS पर निर्माण करने के लिए।

ऐसा करने के लिए, बस WCF संचालित अनुप्रयोग के लिए क्लाइंट साइड कॉन्फ़िग फ़ाइल को संशोधित, configuration/system.serviceModel/client/endpoint/@address में https://server.address साथ http://server.address की जगह,। जैसे इतना:

<configuration> 
    <system.serviceModel> 
    ... 
    <client> 
     <!-- change only the address string --> 
     <endpoint address="https://server.name/Whatever" 
      everything.else.stays.the.same /> 

    </client> 
    </system.serviceModel> 
</configuration> 

(config फ़ाइल का पथ नियमित नेट नियमों के अनुसार बदलता रहता है: क्या यह एक ASPNET एप्लिकेशन या सेवा, या आदि है)

या आप सेट कर सकते हैं कोड में स्पष्ट रूप से पता:

// instantiate new proxy to web service 
    var svc= new ServiceClient(); 
    var e = svc.Endpoint; 
    e.Address = new System.ServiceModel.EndpointAddress("https://server.address/JavaServiceUri"); 

मैं आपको दृढ़ता से सलाह देता हूं कि यह पता कॉन्फ़िगर करने योग्य और हार्ड कोड न हो। इसका मतलब यह नहीं है कि इसे app.config में संग्रहीत किया जाना चाहिए, लेकिन यह बदला जा सकता है। प्रॉक्सी भी।

+0

यह मेरी स्थिति के लिए काम नहीं करता है, यह एक प्रणाली का परिणाम है। संदेश के साथ ArgumentException "प्रदान की गई यूआरआई योजना 'https' अमान्य है; अपेक्षित 'http'।" – RenniePet

2

मुझे लगता है कि आप Basichttpbinding का उपयोग कर रहे हैं। तो फिर तुम दो काम करने की जरूरत है https:

  • परिवर्तन का पता :)
  • सुरक्षा मोड सेट
+0

अच्छा - एक ही प्रश्न से लिंक :) – Rory

+0

@ रोरी, अच्छा पकड़, उत्तर एक वर्ष से अधिक रहा है, आप नोटिस करने वाले पहले व्यक्ति हैं :) –

+0

आपके उत्तर के रूप में स्पष्ट है, यह मुझे संभावित रूप से घंटे बचाता है। 'मुझे लगता है कि आप basichttpbinding का उपयोग कर रहे हैं।' मेरा एसएलएल SOAP के लिए काम कर रहा था, लेकिन यह webHttpBinding -REST के लिए काम नहीं करता है। अब जब मैंने समस्या की पहचान की है, तो मैं ठीक करना शुरू कर सकता हूं :) – Doomsknight

22

परिवहन के लिए मैं एक जवाब MSDN चारों ओर से खुदाई पाया।

<customBinding> 
    <binding name="jsonpBinding"> 
     <jsonpMessageEncoding/> 
     <httpTransport manualAddressing="true"/> 
    </binding> 
</customBinding> 

सेवा

<services> 
    <service name="{YourInfoHere}"> 
     <endpoint address="" binding="customBinding" bindingConfiguration="jsonpBinding" behaviorConfiguration="{YourInfoHere}" contract="{YourInfoHere}"/> 
    </service> 
</services> 

संदर्भित किया गया है कि एक दूसरे बाध्यकारी कि httpsTransport इस्तेमाल किया और फिर एक दूसरे सेवा है जो कि इस्तेमाल जोड़ना:

मेरे मामले में, मैं एक कस्टम बाध्यकारी उपयोग कर रहा था बाध्यकारी चाल है। अंतिम आउटपुट:

<services> 
     <service name="{YourInfoHere}"> 
      <endpoint address="" binding="customBinding" bindingConfiguration="jsonpBinding" behaviorConfiguration="{YourInfoHere}" contract="{YourInfoHere}"/> 
      <endpoint address="" binding="customBinding" bindingConfiguration="jsonpBindingHttps" behaviorConfiguration="{YourInfoHere}" contract="{YourInfoHere}"/> 
     </service> 
    </services> 
    <bindings> 
     <customBinding> 
      <binding name="jsonpBinding"> 
       <jsonpMessageEncoding/> 
       <httpTransport manualAddressing="true"/> 
      </binding> 
      <binding name="jsonpBindingHttps"> 
       <jsonpMessageEncoding/> 
       <httpsTransport manualAddressing="true" /> 
      </binding> 
     </customBinding> 
    </bindings> 

आदर्श नहीं हो सकता है, लेकिन यह काम करता है। एसएसएल काम करने के लिए मैंने ये एकमात्र बदलाव किए थे। चूंकि यह बाध्यकारी & परिवहन में है, इसलिए कोड वही रहता है।

प्रासंगिक MSDN लिंक:

  1. कस्टम बाध्यकारी: http://msdn.microsoft.com/en-us/library/ms731377.aspx
  2. HttpTransport: http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.httptransportbindingelement.aspx
  3. HttpsTransport: http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.httpstransportbindingelement.aspx
+3

+1-वास्तव में जो मैं ढूंढ रहा था :) –