为什么我在将XML数据传递给Web服务时收到错误500

时间:2014-12-17 13:04:57

标签: c# .net xml web-services

在这篇文章中

http://stackoverflow.com/questions/27519558/how-to-pass-http-request-to-web-service?noredirect=1#comment43469479_27519558   
正如dotnetstep所回答的那样,当我传递简单的字符串文本时,这是有效的,但当我更改此代码以传递xml数据时,我收到错误500.请告诉我我在做什么错误

private void button7_Click(object sender, EventArgs e)
    {
        xmlTempData = LoadXML(@"C:\Users\Yogesh\Desktop\receivedPath\File_12.xml");
        string data = "data1="+xmlTempData+"&data2=user2"; //Modified text
        byte[] dataStream = Encoding.UTF8.GetBytes(data);
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:52995/_MyWebService.asmx/HelloWorldNew");
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.ContentLength = dataStream.Length;
        Stream newStream = request.GetRequestStream(); //here getting error 500
        newStream.Write(dataStream, 0, dataStream.Length);
        newStream.Close();
        var reader = new System.IO.StreamReader(request.GetResponse().GetResponseStream());
        string dataReturn = reader.ReadToEnd();
    }

如果我将此行更改为

string data = "data1=hello&data2=user2"; //this is working 

string data = "data1=<tag1>text</tag1>&data2=user2"; //this is returning error 500.

0 个答案:

没有答案