c# - how to pass value in xml for SOAP Request -


i want integrate api not understanding how , value can pass in xml username , password.

 <xsd:element name="login">   <xsd:annotation>     <xsd:documentation>        </xsd:documentation>   </xsd:annotation>   <xsd:complextype>     <xsd:attribute name="username" use="required">       <xsd:simpletype>         <xsd:restriction base="xsd:string">           <xsd:length value="50"/>           <xsd:minlength value="6"/>           <xsd:maxlength value="50"/>         </xsd:restriction>       </xsd:simpletype>     </xsd:attribute>     <xsd:attribute name="password" use="required">       <xsd:simpletype>         <xsd:restriction base="xsd:string">           <xsd:length value="255"/>           <xsd:minlength value="1"/>           <xsd:maxlength value="255"/>         </xsd:restriction>       </xsd:simpletype>     </xsd:attribute>   </xsd:complextype> </xsd:element> 

the document main page http://www.e-courier.com/ecourier/software/schema/xmloverview.html#login . in advance time.

you're looking @ xsd schema of login element. schema describes how request should like.

on page linked see how login request in xml shaped:

<login username='test' password='test' />  

as service picky on how xml shaped (it matter example how namespace prefixes named, assume implementation error on part) have used xmlserializer , matching dto objects working.

notice how add xmlserializernamespaces , prefixes required.

// setup dto var s = new envelope {   body = new body {      login = new login {        username = "test" ,        password = "test" ,        website = "ecourier"      }   } };  // setup namespaces , prefixes     var ns = new xmlserializernamespaces(); ns.add("soap", "http://schemas.xmlsoap.org/soap/envelope/"); ns.add("m","http://www.e-courier.com/software/schema/public/");  // create serializer var ser = new xmlserializer(typeof(envelope));  using(var ms = new memorystream()) {     // write dto memorystream     ser.serialize(ms, s, ns);      using(var wc = new webclient()) {        wc.encoding = system.text.encoding.utf8;        var resp = wc.uploaddata(           "http://www.e-courier.com/ecourier/software/xml/xml.asp",           ms.toarray()      );      console.writeline(encoding.utf8.getstring(resp));     } } 

here dto classes match serialization structure xml payload:

[xmlroot("envelope", namespace="http://schemas.xmlsoap.org/soap/envelope/")] public class envelope {     [xmlelement("body", namespace="http://schemas.xmlsoap.org/soap/envelope/")]     public body body { get; set; } }  public class body {     [xmlelement("login", namespace="http://www.e-courier.com/software/schema/public/")]     public login login { get; set; } }  public class login {     [xmlattribute("username")]     public string username { get; set; }     [xmlattribute("password")]     public string password { get; set; }     [xmlattribute("website")]     public string website { get; set; } } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -