i need a web service that accepts POST methods. An server that is accessing me is using POST method. It sends me an xml and i should response with some xml.
The other way, when i'm accessing him, i have managed with HttpWebRequest class and it works fine. It is done like:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(s.strMvrataUrl.ToString());
req.ClientCertificates.Add(cert);
req.Method = "POST";
req.ContentType = "text/xml; encoding='utf-8'";
s.AddToLog(Level.Info, "Certifikat dodan.");
byte[] bdata = null;
bdata = Encoding.UTF8.GetBytes(strRequest);
req.ContentLength = bdata.Length;
Stream stremOut = req.GetRequestStream();
stremOut.Write(bdata, 0, bdata.Length);
stremOut.Close();
s.AddToLog(Level.Info, "Request: " + Environment.NewLine + strRequest);
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
strResponse = streamIn.ReadToEnd();
streamIn.Close();
Now i would like to have a webservice that accepts POST method. Does anyone has an idea how to do this. I'm stuck here.
From http://support.microsoft.com/kb/819267:
HTTP GET and HTTP POST may be enabled in the configuration. There exists a file called webconfig file in the root where in you have to add the following setting:
ie inside the system.web tag.
Now in the web-service if you are intending to send an XML back you could design a struct of your wish which resembles the anticipated XML. eg: To get an XML of following type:
you have to return an object of following struct from the web-service:
Now this can be received as response as string and then be parsed as you like.
===============================================================================
Edit I
The following is a HelloWorld WebMethod
[in case of struct change the return type to corresponding struct type]
The following is a function where you can POST to a URL and also send a xml file to the webservice[Use according to your need]:
And the call would be like :
[If this was helpful or need more help please let me know]