I want to create a API that takes XML as argument. I want to host that in a sub domain called abc.xyz.com and give that to my sub company.
I have created the WEB API using MVC-4. A controller called NewRequest that have a post method like this
[HttpPost]
public string Post(System.Net.Http.HttpRequestMessage request)
{
XmlDocument doc = new XmlDocument();
doc.Load(request.Content.ReadAsStreamAsync().Result);
string xmlstring= doc.InnerText.ToString();
// Then a lot of Logic and finally return the string
return xmlstring;
}
then i have hosted the API and i tried to call the API from a web page. But on doing so i am getting an 500 error.
private void send(XmlDocument doc, string url)
{
string xml = doc.OuterXml.ToString();
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.KeepAlive = false;
req.ProtocolVersion = HttpVersion.Version10;
req.ServicePoint.ConnectionLimit = 1;
byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(xml);
req.Method = "POST";
req.ContentType = "application/xml";
Stream requestStream = req.GetRequestStream();
requestStream.Write(requestBytes, 0, requestBytes.Length);
requestStream.Close();
WebResponse res = (WebResponse)req.GetResponse();
Stream responseStream = (res.GetResponseStream());
}
Can anybody tell me what will be the issue, your support is highly appreciated.
Thanks
RK
Aucun commentaire:
Enregistrer un commentaire