Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi there,
Iam trying to build WPF program to create Soap requests as xml files according to the WSDL which is added as service reference, the problem is that i could not configure the proxy class to use that xml file and send it as a request as well as receiving the response .it gives me an exception :
An unhandled exception of type 'System.ServiceModel.FaultException`1' occurred in mscorlib.dll Additional information: APPLICATION ERROR

public string returnSerializedxml(object input)
{
XmlSerializer xmlSerializer = new XmlSerializer(input.GetType());

using (StringWriter textWriter = new StringWriter())
{
xmlSerializer.Serialize(textWriter, input);
return textWriter.ToString();
}
}

private void button1_Click(object sender, RoutedEventArgs e)
{
ConsignmentEndpointClient proxy = new ConsignmentEndpointClient();
save sv = new save();
saveResponse response = new saveResponse();
XmlDocument doc = new XmlDocument();
doc.Load(PATH);
response= proxy.save(sv); /*Here occur the exception*/

try
{
Output.Text = "Response : \n" + returnSerializedxml(response);
}
catch (Exception error)
{
Output.Text = "Error in Request : \n" + error;
}

What I have tried:

Iam not sure but something is missing like FileStream or similar, I would be thankful for any hint .
Posted
Updated 11-Oct-16 2:04am

1 solution

Try below code, If I understand your query correctly.
pass your xml to Soapcommand

C#
private string ProcessRequest(string SoapCommand)
   {
       string soapResult = string.Empty;
       try
       {
           WebRequest webRequest = CreateWebRequest();
           XmlDocument soapEnvelopeXml = new XmlDocument();
           soapEnvelopeXml.LoadXml(SoapCommand);


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

           using (WebResponse response = webRequest.GetResponse())
           {
               using (StreamReader rd = new StreamReader(response.GetResponseStream()))
               {
                   soapResult = rd.ReadToEnd();
               }
           }
       }
       catch (Exception)
       {
           throw;
       }
       return soapResult;
   }

   public static HttpWebRequest CreateWebRequest()
   {
       HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(@"http://111.11.31.116:45259/ilws/LinkSOAP");
       webRequest.Headers.Add(@"SOAP:Action");
       webRequest.ContentType = "text/xml;charset=\"utf-8\"";
       webRequest.Accept = "text/xml";
       webRequest.Method = "POST";
       return webRequest;
   }
 
Share this answer
 

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