2012-08-07 37 views
5

मुझे एक एसओएपी सेवा मिली है जिसे मैं कनेक्ट करना चाहता हूं। इसे गंदे https तक पहुंचाया जाना चाहिए और इसे प्रमाण पत्र द्वारा हस्ताक्षरित निकाय की आवश्यकता है। इस प्रकारएचटीटीपीएस पर डब्ल्यूसीएफ और शरीर पर हस्ताक्षर

<basicHttpBinding> 
    <binding name="P4Binding" closeTimeout="00:01:00" openTimeout="00:01:00" 
     receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" 
     bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
     maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
     messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
     useDefaultWebProxy="true"> 
     <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
      maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
     <security mode="TransportWithMessageCredential"> 
     <transport clientCredentialType="None" proxyCredentialType="None" 
      realm="" /> 
     <message clientCredentialType="Certificate" algorithmSuite="Default" /> 
     </security> 
    </binding> 
</basicHttpBinding> 

सेटअप अप मेरे मुवक्किल:

P4_ServiceReference.P4PortTypeClient client = new P4_ServiceReference.P4PortTypeClient(); 

client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; 
client.ClientCredentials.ServiceCertificate.DefaultCertificate = new X509Certificate2(@"[..].cer"); 
client.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2(@"[..]", "somepass"); 

यहाँ तक कि मेरे Reference.cs बदल ServiceContractAttribute और OperationContractAttribute पर ProtectionLevel=ProtectionLevel.Sign शामिल करने के लिए

मैं निम्नलिखित कोड की कोशिश की है।

क्या होता है कि wse: सुरक्षा हेडर बनाया गया है, लेकिन शरीर पर हस्ताक्षर नहीं किए जा रहे हैं। सेवा लौटाती है।

मुझे क्या याद आ रहा है ताकि शरीर ठीक से हस्ताक्षर हो जाए?

उत्तर

8

basicHttpBinding के बजाय इस customBinding का उपयोग करके इसे ठीक किया गया।

 //Setup custom binding with HTTPS + Body Signing + Soap1.1 
     CustomBinding binding = new CustomBinding(); 

     //HTTPS Transport 
     HttpsTransportBindingElement transport = new HttpsTransportBindingElement(); 

     //Body signing 
     AsymmetricSecurityBindingElement asec = (AsymmetricSecurityBindingElement)SecurityBindingElement.CreateMutualCertificateBindingElement(MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10); 
     asec.SetKeyDerivation(false); 
     asec.AllowInsecureTransport = true; 
     asec.IncludeTimestamp = true; 

     //Setup for SOAP 11 and UTF8 Encoding 
     TextMessageEncodingBindingElement textMessageEncoding = new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8); 

     //Bind in order (Security layer, message layer, transport layer) 
     binding.Elements.Add(asec); 
     binding.Elements.Add(textMessageEncoding); 
     binding.Elements.Add(transport); 

ऐसा लगता है कि TransportWithMessageCredential केवल सुरक्षा के लिए परिवहन का उपयोग करता है और बाकी सब कुछ अनदेखा करता है।

+1

मैंने केवल शरीर पर हस्ताक्षर करने का प्रयास किया, लेकिन AsymmetricSecurityBindingElement का उपयोग करके अभी भी इसे एन्क्रिप्ट करता है (सेवा https का उपयोग नहीं करती है)। मेरे यहां एक प्रश्न है: http://stackoverflow.com/questions/20349062/wcf-client-binding-to-sign-the-body-of-a-request-to-a-java-web- सेवा –

+0

@MrShoubs अपने सेवा इंटरफ़ेस में निम्न विशेषता लागू करें और एन्क्रिप्शन अब और नहीं होगा, '[ServiceContractAttribute (ProtectionLevel = ProtectionLevel.Sign, ...)] सार्वजनिक इंटरफ़ेस MyService {...} '। ध्यान दें कि यह कोड से भी किया जा सकता है जैसे 'myService.Endpoint.Contract.ProtectionLevel = ProtectionLevel.Sign'। –