Is SOAP Http POST more complicated than I thought
Posted
by
Pete Petersen
on Programmers
See other posts from Programmers
or by Pete Petersen
Published on 2013-05-31T08:25:34Z
Indexed on
2013/10/26
16:08 UTC
Read the original article
Hit count: 284
I'm currently writing a bit of code to send some xml data to a web service via HTTP POST. I thought this would be really simple and have written the following example code (C#)
Console.WriteLine("Press enter to send data...");
while (Console.ReadLine() != "q")
{
HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(@"http://localhost:8888/");
Foo fooItem = new Foo
{
Member1 = "05",
Member2 = "74455604",
Member3 = "15101051",
Member4 = 1,
Member5 = "fsf",
Member6 = 6.52,
};
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = fooItem.ToXml();
byte[] data = encoding.GetBytes(postData);
httpWReq.Method = "POST";
httpWReq.ContentType = "application/xml";
httpWReq.ContentLength = data.Length;
using (Stream stream = httpWReq.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Received " + responseString);
Console.WriteLine("Press enter to send data...");
}
This is all I thought would be necessary, however I have now been given the details for the web service. This included some information which is unfarmiliar to me and I'm unsure whether I need to include it.
The information I was sent was
<url>http://sometext/soap/rpc</url>
<namespace>http://sometext/a.services</namespace>
<method>receiveInfo</method>
<parm-id>xmldata</parm-id> (Input data) (Actual XML data as string)
<parm-id>status</parm-id> (Output data)
<userid>user</userid>
<password>pass</password>
<secure>false</secure>
I guess this means I need to include a username and password somehow, but I'm not sure what the namespace or method fields are used for.
Could anyone give me a hint? Sorry I've never used webservices before.
© Programmers or respective owner