2016-03-23 11 views
1

Ich versuche, einen SOAP-Aufruf an einen Webdienst zu machen.WCF C# Soap-Dienst wird nicht korrekt gerendert

das Handbuch Nach dem SOAP-Aufruf sollte wie folgt aussehen:

<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wsswssecurity-secext-1.0.xsd" 

xmlns:wsa="http://www.w3.org/2005/08/addressing" 


xmlns:vh="http://vedaxml.com/soap/header/v-header-v1-9.xsd" 


xmlns:idm="http://vedaxml.com/vxml2/idmatrix-v4-0.xsd"> 

<soapenv:Header> 



<wsse:Security> 
<wsse:UsernameToken> 
    <wsse:Username>****</wsse:Username> 
    <wsse:Password>****</wsse:Password> 
</wsse:UsernameToken> 
</wsse:Security> 
<wsa:ReplyTo> 
<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous 
</wsa:Address> 
</wsa:ReplyTo> 
<wsa:To>http://vedaxml.com/sys2/idmatrix-v4</wsa:To> 
<wsa:Action>http://vedaxml.com/idmatrix/VerifyIdentity</wsa:Action> 
<wsa:MessageID>Quick_Request_1</wsa:MessageID> 
</soapenv:Header> 
<soapenv:Body> 
    <idm:request client-reference="Quick Connect Ref" 
          reason-for-enquiry="Quick Connect"> 
<idm:individual-name> 
    <idm:family-name>Potter</idm:family-name> 
    <idm:first-given-name>Harry</idm:first-given-name> 
    <idm:other-given-name>James</idm:other-given-name> 
    </idm:individual-name> 
    <idm:date-of-birth>1980-07-31</idm:date-of-birth> 
    <idm:current-address> 
<idm:property>Potter Manor</idm:property> 
    <idm:unit-number>3</idm:unit-number> 
    <idm:street-number>4</idm:street-number> 
    <idm:street-name>Privet</idm:street-name> 
    <idm:street-type>Drive</idm:street-type> 
    <idm:suburb>Little Whinging</idm:suburb> 
    <idm:state>NSW</idm:state> 
    <idm:postcode>2999</idm:postcode> 
    </idm:current-address> 
    </idm:request> 
</soapenv:Body> 
</soapenv:Envelope> 

Das Unternehmen mir mit einer WSDL-Datei zur Verfügung gestellt hat. Was ich in C# sowohl als Service-Referenz als auch als Web-Referenz importiert habe (

) Zuerst versuchte ich eine Service-Referenz, in web.config wurden keine Bindungen erstellt, als ich die WSDL importierte Datei, also habe ich programmatisch die Bindungen hinzugefügt. Das ist mein Code:

BasicHttpsBinding binding = new BasicHttpsBinding(securityMode: BasicHttpsSecurityMode.TransportWithMessageCredential); 
      EndpointAddress address = new EndpointAddress("https://ctaau.vedaxml.com/cta/sys2/idmatrix-v4"); 

      ServiceReference1.identitydetails idDetails = new ServiceReference1.identitydetails();    
      ServiceReference1.IdMatrixPortTypeClient client = new ServiceReference1.IdMatrixPortTypeClient(binding, address); 
      ServiceReference1.request request = new ServiceReference1.request(); 
      request.individualname = new ServiceReference1.individualnameType(); 
      request.individualname.familyname = "Doe"; 
      request.individualname.firstgivenname = "John"; 
      request.dateofbirth = new DateTime(1982, 6, 30); 

      client.ClientCredentials.UserName.Password = "myPassword"; 
      client.ClientCredentials.UserName.UserName = "myUsername"; 
      var response = client.IdMatrixOperation(request); 

Das Resposne fehlgeschlagen, also habe ich den POST mit Fiddler überprüft. Es war völlig anders als die erforderliche Post.

Fiddler hat mir gezeigt:

POST https://ctaau.vedaxml.com/cta/sys2/idmatrix-v4 HTTP/1.1 Content-Type: text/xml; charset = utf-8 Soapaction: "http://vedaxml.com/idmatrix/VerifyIdentity" Host: ctaau.vedaxml.com Content-Length: 1216 erwarten: 100-Continue Accept-Encoding: Verbindung gzip, deflate: Keep-Alive

<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/2Z+y84o0RBobFBWyoF5bwAAAAAMq+GwwIcokm+lVAU/kPq4mJScS+4yh9ElAQSyM2iUqMACQAA</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-23T01:23:53.921Z</u:Created> 
       <u:Expires>2016-03-23T01:28:53.921Z</u:Expires> 
      </u:Timestamp> 
      <o:UsernameToken u:Id="uuid-f3068a37-421c-4b81-93c6-ef622def918a-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">myPassword</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"> 
     <request xmlns="http://vedaxml.com/vxml2/idmatrix-v4-0.xsd"> 
      <individual-name> 
       <family-name>Doe</family-name> 
       <first-given-name>John</first-given-name> 
      </individual-name> 
     </request> 
    </s:Body> 
</s:Envelope> 

Wie Sie sehen, ist der WSSE-Namespace nicht korrekt. Ich habe keine WS-Adressierung und die Präfixe sind alle falsch?

Also zog ich nach einer Web-Referenz. Ich musste WS-Secrutiy arbeiten lassen, also änderte ich das Client-Protokoll zu WebServicesClientProtocol.

Dies ist mein Code:

WebReference.idmatrix idMatrix = new WebReference.idmatrix(); 
      WebReference.request request = new WebReference.request(); 
      request.individualname = new WebReference.individualnameType(); 
      request.individualname.familyname = "Potter"; 
      request.individualname.othergivenname = names; 
      request.individualname.firstgivenname = "Harry"; 
      request.dateofbirth = new DateTime(1980, 7, 31); 


      UsernameToken userToken = new UsernameToken("myusername", "mypassword", PasswordOption.SendPlainText); 

      SoapContext requestContext = idMatrix.RequestSoapContext; 
      requestContext.Security.Tokens.Add(userToken); 

      var test = idMatrix.IdMatrixOperation(request); 

Die Post in Fidder wie folgt aussieht:

POST https://vedaxml.com/sys2/idmatrix-v4 HTTP/1.1 
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 4.0.30319.42000) 
VsDebuggerCausalityData: uIDPo+bosvSda9ZIvNIXrG1tEbIAAAAAH4GKWz0+uU2A4pOErBrkw2fytXzxQh9Jp4TpqUiqXHoACQAA 
Content-Type: text/xml; charset=utf-8 
SOAPAction: "http://vedaxml.com/idmatrix/VerifyIdentity" 
Host: vedaxml.com 
Content-Length: 1768 
Expect: 100-continue 
Connection: Keep-Alive 

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
    <soap:Header> 
     <wsa:Action>http://vedaxml.com/idmatrix/VerifyIdentity</wsa:Action> 
     <wsa:MessageID>uuid:d1a0cf65-cee3-467d-9f98-b72cbd3d4e5a</wsa:MessageID> 
     <wsa:ReplyTo> 
      <wsa:Address>http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous</wsa:Address> 
     </wsa:ReplyTo> 
     <wsa:To>https://vedaxml.com/sys2/idmatrix-v4</wsa:To> 
     <wsse:Security soap:mustUnderstand="1"> 
      <wsu:Timestamp wsu:Id="Timestamp-5fbc1707-8d36-4091-804d-4c19ec06f7bd"> 
       <wsu:Created>2016-03-23T01:26:31Z</wsu:Created> 
       <wsu:Expires>2016-03-23T01:31:31Z</wsu:Expires> 
      </wsu:Timestamp> 
      <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-4803d49a-e2c3-45f5-bf18-7c0b5cd7d130"> 
       <wsse:Username>myusername</wsse:Username> 
       <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">mypassword</wsse:Password> 
       <wsse:Nonce>sc5Dgf/vhU+YTZjdLQZsLw==</wsse:Nonce> 
       <wsu:Created>2016-03-23T01:26:31Z</wsu:Created> 
      </wsse:UsernameToken> 
     </wsse:Security> 
    </soap:Header> 
    <soap:Body> 
     <request xmlns="http://vedaxml.com/vxml2/idmatrix-v4-0.xsd"> 
      <individual-name> 
       <family-name>Potter</family-name> 
       <first-given-name>Harry</first-given-name> 
       <other-given-name>James</other-given-name> 
      </individual-name> 
     </request> 
    </soap:Body> 
</soap:Envelope> 

Es ist ein wenig näher, aber einige der Namensräume sind immer noch falsch, und die prefexis sind auch falsch .

Es muss soapenv werden: und in dem Körper braucht i.Tr. sein:

Wie kann ich fix die Namespaces und Präfix ist in C#?

+0

Haben Sie versucht, den Proxy mit dem Dienstprogramm 'wsdl.exe' zu ​​generieren? Dies sollte mit der WSDL-Datei übereinstimmen, die es gegeben hat, und dann ist es ziemlich geradlinig –

Antwort

0

So habe ich endlich mein Problem gelöst. Ich werde alles, was ich gelernt habe, veröffentlichen. Prefix's bedeuten zunächst gar nichts. und dasselbe sind, das Präfix bezieht sich nur auf den Namespace heißt:

xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" = <s:envelope> 
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" = <soap:envelope> 

diese beiden sind gleichwertig.

Zweitens, was ich brauchte, war WS-Security zu tun bekommen und WS-Addressing und Seife V1.1 (nicht v1.2) arbeiten, da dies vom Server erforderlich war. Um dies zu tun, musste ich eine benutzerdefinierte Bindung erstellen. Im Web.config:

<system.serviceModel> 
<bindings> 
    <customBinding> 
    <binding name="WsHttpSoap11"> 
     <textMessageEncoding messageVersion="Soap11WSAddressing10"></textMessageEncoding> 
     <security authenticationMode="UserNameOverTransport" 
     messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11" 
     securityHeaderLayout="Lax" 
     includeTimestamp="false" 
     requireDerivedKeys="false" > 
     </security> 
     <httpsTransport></httpsTransport> 
    </binding> 
    </customBinding> 
</bindings> 
<client> 
    <endpoint address="<my endpoint url>" binding="customBinding" bindingConfiguration="WsHttpSoap11" contract="ServiceReference1.IdMatrixPortType" name="testBinding" ></endpoint> 
</client> 

überprüfte ich die Ausgabe mit Fiddler, und alle die richtigen Namensraum erstellt wurden.

Zusammenfassend hoffe ich, dass jeder in Zukunft von SOAP weggeht und in Richtung Oauth + RESTfull Anwendungen läuft.