C# .NET - POST request in C# language to an Apache server using SOAP

Asked By Oswaldo Gonzalez on 01-Feb-13 10:52 AM
Im trying to make a POST request in C# language to an Apache server using SOAP. I need to know how to accomplish that in C#. If any can help me where can I find information about that? 

Here is what I have so far:

01.{
02.   
03.  // Create a request
04.   
05.  HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://webservice.emida.net/soap/servlet/rpcrouter");
06.   
07.   
08.   
09.  // Set the Method property of the request to POST.
10.  request.Method = "CommTest";
11.   
12.  // Create POST data and convert it to a byte array.
13.  string postData = "";
14.  byte[] byteArray = Encoding.ASCII.GetBytes(postData);
15.  // Set the ContentType property of the WebRequest.
16.  request.ContentType = "urn:debisys-soap-services";
17.  request.Accept = "text/xml";
18.      
19.  // Set the ContentLength property of the WebRequest.
20.  request.ContentLength = byteArray.Length;
21.   
22.  // Get the request stream.
23.  Stream dataStream = request.GetRequestStream();
24.   
25.  // Write the data to the request stream.
26.  dataStream.Write(byteArray, 0, byteArray.Length);
27.  // Close the Stream object.
28. 
29.  Label2.Text = dataStream.ToString();
30. 
31.  dataStream.Close();
32.   
33.  //Get response
34.  WebResponse response = request.GetResponse();
35.   
36.  //Get the stream containing content
37.  dataStream = response.GetResponseStream();
38.  //Open the stream
39.  StreamReader reader = new StreamReader(dataStream);
40.  //Read content
41.  string responseFromServer = reader.ReadToEnd();
42.  //Display the content
43.  Label1.Text = responseFromServer;
44.  //Clean up the streams
45.  reader.Close();
46.  dataStream.Close();
47.  response.Close();
48.}

With "CommTest" I should be able to send "None" and receive an "OK". The error that I have is 

(501) Not Implemented


I guess that means that Im not sending it properly. But I dont know how to accomplish a SOAP request and response. 

Thank you,

Oswaldo
Robbe Morris replied to Oswaldo Gonzalez on 01-Feb-13 11:22 AM
That message typically means that your SOAP message is attempting to call a method that doesn't exist.  You'd have to post the contents of your SOAP formatted xml in your postData variable.
Irbaz Hashmi replied to Oswaldo Gonzalez on 02-Feb-13 08:28 AM
request.Method = "CommTest";
make this 

request.Method = "POST";
Robbe Morris replied to Robbe Morris on 02-Feb-13 09:12 AM
Good catch!  Cannot believe I did not see that myself.