2016-03-18 14 views
5

पास करें मैं सेवा संदर्भ का उपयोग कर सी # एसएसओ एसओएपी सेवा होस्ट से कनेक्ट करने की कोशिश कर रहा हूं। यह मेरा अनुरोध संदेश है:"सेवा संदर्भ" के माध्यम से एसएसएल एसओएपी होस्ट से कनेक्ट करें और सुरक्षा शीर्षलेख

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
    <s:Header> 
     <VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPo/zwMmtdsVhFsAVDkQbiV/4AAAAA1zXtnc72UEm+4tlKzvCxsvN6OC2prvRIljIX4XzHKEYACQAA</VsDebuggerCausalityData> 
     <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
      <u:Timestamp u:Id="_0"> 
       <u:Created>2016-03-18T12:45:27.558Z</u:Created> 
       <u:Expires>2016-03-18T12:50:27.558Z</u:Expires> 
      </u:Timestamp> 
      <o:UsernameToken u:Id="uuid-2c7986ba-eee5-4411-90a9-a02b625c55ff-1"> 
       <o:Username>MyUserName</o:Username> 
       <o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">MyPlainPassword</o:Password> 
      </o:UsernameToken> 
     </o:Security> 
    </s:Header> 
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
     <generateId xmlns="http://com.vedaadvantage/dp3/Enterprise/StandardTradeCreditCommercial/IndividualCommercialService"/> 
    </s:Body> 
</s:Envelope> 

यह संदेश मेरी सेवा की मेजबानी के लिए भेजता है। लेकिन होस्ट नीचे जैसा देता है:

सुरक्षा प्रोसेसर संदेश में सुरक्षा शीर्षलेख नहीं ढूंढ पाया। ऐसा इसलिए हो सकता है क्योंकि संदेश एक असुरक्षित गलती है या क्योंकि संचार पक्षों के बीच बाध्यकारी विसंगति है। यह तब हो सकता है जब सेवा सुरक्षा के लिए कॉन्फ़िगर की गई हो और ग्राहक सुरक्षा का उपयोग नहीं कर रहा है।

यह मेरा कॉन्फ़िग फ़ाइल है:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 

    <system.serviceModel> 

    <bindings> 
     <customBinding> 
     <binding name="myBinding"> 
      <textMessageEncoding messageVersion="Soap11" /> 
      <security authenticationMode="UserNameOverTransport" 
        messageSecurityVersion="WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10" > 
      </security> 

      <httpsTransport /> 
     </binding> 
     </customBinding> 
    </bindings> 
    <client> 
     <endpoint address="https://{URL}" 
     binding="customBinding" 
       bindingConfiguration="myBinding" 
     contract="ServiceReference2.MyService" 
       name="IndividualCommercialService" /> 
    </client> 
    </system.serviceModel> 
</configuration> 

हालांकि जब मैं SOAPUI या अन्य HTTP पोस्ट विधियों के माध्यम से एक ही एक्सएमएल भेजने यह ठीक काम करता है।

मैं भी निकालने और प्रमाण पत्र और उपयोगकर्ता संबद्ध/के रूप में नीचे से गुजरती हैं:

private static X509Certificate2 DownloadSslCertificate(string strDNSEntry) 
     { 

      X509Certificate2 cert = null; 
      using (TcpClient client = new TcpClient()) 
      { 
       //ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;   
       client.Connect(strDNSEntry, 443); 

       SslStream ssl = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null); 
       try 
       { 
        ssl.AuthenticateAsClient(strDNSEntry); 
       } 
       catch (AuthenticationException e) 
       { 
        //log.Debug(e.Message); 
        ssl.Close(); 
        client.Close(); 
        return cert; 
       } 
       catch (Exception e) 
       { 
        //log.Debug(e.Message); 
        ssl.Close(); 
        client.Close(); 
        return cert; 
       } 
       cert = new X509Certificate2(ssl.RemoteCertificate); 
       ssl.Close(); 
       client.Close(); 
       return cert; 
      } 
     } 

     private static void Main(string[] args){ 
       var proxy = new MyService(); 

       var uri = proxy.Endpoint.Address.Uri; 
       var cer = DownloadSslCertificate(uri.DnsSafeHost); 

       EndpointIdentity identity = EndpointIdentity.CreateDnsIdentity(cer.Subject.Replace("CN=", "")); 
       EndpointAddress address = new EndpointAddress(proxy.Endpoint.Address.Uri, identity); 

       proxy.Endpoint.Address = address; 

       proxy.ClientCredentials.UserName.UserName = "MyUserName"; 
       proxy.ClientCredentials.UserName.Password = "MyPlainPassword"; 
       proxy.ClientCredentials.ServiceCertificate.DefaultCertificate = cer; 

       proxy.HellowWorld(); 
      } 

मैं यकीन नहीं है कि विधि है कि मैं प्रमाण पत्र मिल रहा है सही है या नहीं और यह भी कारण है कि HTTP पोस्ट काम करता है लेकिन नहीं कर रहा हूँ मेरी सेवा संदर्भ कॉल नहीं करता है।

आपकी मदद के लिए अग्रिम धन्यवाद।

चीयर्स

उत्तर

1

कोशिश आदेश छिपी हुई फ़ाइलें देखने के लिए पहले समाधान एक्सप्लोरर में दिखाएँ सभी फ़ाइलें चयन में डबल्यूएसडीएल (सेवा संदर्भ) अंदर देखने के लिए। आप 'll से अंदर सेवा संदर्भ Reference.svcmap -> Reference.cs, और इस फ़ाइल के अंदर जोड़ने ProtectionLevel = System.Net.Security.ProtectionLevel.Sign के रूप में नीचे

[System.ServiceModel.ServiceContractAttribute(Namespace = "http://www.your.url/Service/", ConfigurationName = "Service.Service", ProtectionLevel = System.Net.Security.ProtectionLevel.Sign)] 

पता चला है कि मदद करनी चाहिए आप। आमतौर पर ऑटोगनेरेटेड प्रॉक्सी को संशोधित करना वास्तव में बुरा विचार है, लेकिन ऐसा लगता है कि यह एकमात्र विकल्प है।

+0

धन्यवाद व्लादिमीर, मैं इसका परीक्षण करूंगा और आपको वापस ले जाऊंगा। – Barsham

+0

आपका स्वागत है, कृपया मुझे परिणामों के बारे में सूचित करें – Vladimir

संबंधित मुद्दे

 संबंधित मुद्दे