Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to send some XML DATA to web service via POST Command , I have no information about the webserice or anything at all , i only know that i need to send a XMLstream to it , i know the server IP adress and the port , the XML tree of the parameters. and that all , I am a bet lost on how to consumme this web service and get the response . I've never worked with Web services so please understand if my code have some major errors and kindly guide me :
C#
public  void Execute()
    {
        HttpWebRequest request = CreateWebRequest();
        XmlDocument soapEnvelopeXml = new XmlDocument();
        soapEnvelopeXml.LoadXml(@"<?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"">

         <soap:Body> 

                    <mergeprofiles xmlns=""http://127.0.0.1:90"">
                    <Profile>
                    <Member>278615</Member>
                    <ExtRef>003D000001StY68IAF</ExtRef>zs 
                    <Name>LESCA</Name>
                    <ChangedBy>user</ChangedBy>
                    <FirstName>Paolo</FirstName>
                    <Street1>via magnanina 3947</Street1>
                     <Street2></Street2>
                    <Street3></Street3>
                    <City>VIGEVANO</City>
                    <ZIP>27029</ZIP>
                    <EMail>test@test.it</EMail>
                    <Phone></Phone>
                    <MobilePhone>+39331231233</MobilePhone>
                    <Fax></Fax>
                    <ISOLanguage>en</ISOLanguage>
                    <Salut1>Mr</Salut1>
                    <Homepage></Homepage>
                    <VATNo1>0</VATNo1>
                    </Profile>
                    <EndOfMessage>@@@</EndOfMessage>
                    </mergeprofiles>

</soap:Body>

</soap:Envelope>");


using (Stream stream = request.GetRequestStream())
        {
            soapEnvelopeXml.Save(stream);
        }

        using (WebResponse response = request.GetResponse())
        {
            using (StreamReader rd = new StreamReader(response.GetResponseStream()))
            {
                string soapResult = rd.ReadToEnd();
                Console.WriteLine(soapResult);
            }
        }
    }
    /// <summary>
    /// Create a soap webrequest to [Url]
    /// </summary>
    /// <returns></returns>
    public HttpWebRequest CreateWebRequest()
    {
        HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(@"http://127.0.0.1:90/");
        webRequest.Headers.Add(@"SOAP:Action");
        webRequest.ContentType = "text/xml;charset=\"utf-8\"";
        webRequest.Accept = "text/xml";
        webRequest.Method = "POST";
        return webRequest;
    }


The probeme is when ever i call Execute () in page_load , it runs and runs and never stops, . The web service is working when i call using others methods , i don't know how or why is that hapenning, can you please help ?
Posted
Comments
[no name] 29-Aug-14 14:20pm    
Learn how to run code in a debugger and find out why "it runs and runs and never stops", whatever that means. Curious as to why you are using code that would never work in a web application, in a web application.
Sergey Alexandrovich Kryukov 29-Aug-14 14:55pm    
Why without WSDL?
—SA
Subramanyam Shankar 7-Mar-15 11:35am    
Interesting .I'm curious to know why you are using this approach.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900