Click here to Skip to main content
15,878,809 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello everyone i am converting one classic asp legacy application into .net I am stuck at this point where i need to call a webservice located at a url. I am able to do this by adding a web reference but the response that i am getting is a string.I need an xml so that i can bind that into a grid. so when i am using this code
C#
  public  void Execute()
     {
    var url ="http://sun2205.daytonoh.ncr.com:7780/NCROMeOrderInterfaceApl-
     NCROMeOrderInterfaceproj-context-root/NCROMeOrderInterfaceWSSoapHttpPort";    
    HttpWebRequest request = CreateWebRequest(url);
    XmlDocument soapEnvelopeXml = new XmlDocument();

   soapEnvelopeXml.LoadXml(@"
     
     <ns1:customerdataelement xmlns:ns1="#unknown">
    
    <![CDATA[
     
  <customer>
  <site>
  <customer_no>7435535</customer_no>
 <site_uses>DELIVER_TO</site_uses>
  <name>GREAT SCOTTS EATERY</name>
   <address>1551 CORTEZ ST</address>
  <city>DENVER</city>
  <state>CO</state>
  <zip>0221-6908</zip> <primary_flag></primary_flag>
  <primary_ship_flag></primary_ship_flag>
   </site>
  </customer>
   
      
    </ns1:customerdataelement>
    
    ");



    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);
        }
    }
}

public HttpWebRequest CreateWebRequest(String ASMXURL) 
{
    HttpWebRequest webRequest2 = null;
    try
    {
          String action = "\"http://ncrerpjndi/NCROMeOrderInterfaceWS.wsdl/customerData\"";
        webRequest2 = (HttpWebRequest)WebRequest.Create(ASMXURL);
        webRequest2.UserAgent = ".NET Framework Test Client";
        webRequest2.Headers.Add("SOAPAction", action);
        //webRequest2.Headers.Add("Accept-Encoding", "gzip,deflate") ;
        webRequest2.ContentType = "text/xml;charset=UTF-8";
        webRequest2.Method = "POST";
       // return webRequest2;
    }
    catch (WebException wex)
    {
        var pageContent = new StreamReader(wex.Response.GetResponseStream())
                              .ReadToEnd();
        Response.Write(pageContent);
    }
return webRequest2;

}


I am calling this function on button click but getting an error (500) Internal Server Error.

What to do.I can access the service using web reference but the string response could not be bind to grid properly.A string response is basically an address string which contains name,city ,adrress ,zip but split can not be used here since there are no proper spaces in this string Hence need an xml response.Any help would be appreciated.we
Posted
Updated 22-Jun-15 4:24am
v2
Comments
sashje- 23-Jun-15 3:53am    
Doesn't your code show generate errors when compiling? The soapEnvelopeXml.LoadXml contains a string where the "#uknown" is not escaped, and should be written \"#unknown\"

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