Публикация XML-данных в веб-сервис с использованием C # - PullRequest
0 голосов
/ 22 марта 2012

Я пытаюсь опубликовать набор данных XML в своем веб-сервисе, но получаю ошибку 500 при попытке отправить XML, если я заменяю postData = "xmlMsg = Test", веб-сервис принимает его нормально, но не когда я пытаюсь отправить XML

в моем веб-сервисе я использую

    [WebMethod]
    public string HelloWorld(string xmlMsg)
    {.......

мое приложение использует

    URL = "http://localhost:55310/Service1.asmx/HelloWorld";
    method = "POST";
    postData = "xmlMsg=<NewDataSet> <People><PersonId>3293</PersonId> </People></NewDataSet>"

    public static string WRequest(string URL, string method, string postData)
    {
        string responseData = "";

        try
        {
            HttpWebRequest hwrequest = (HttpWebRequest)WebRequest.Create(URL);
            hwrequest.Timeout = 60000;
            hwrequest.Method = method;
            hwrequest.KeepAlive = false;

            if (hwrequest.Method == "POST")
            {
                hwrequest.ContentType = "application/x-www-form-urlencoded";

                UTF8Encoding encoding = new UTF8Encoding();
                byte[] postByteArray = encoding.GetBytes(postData);
                hwrequest.ContentLength = postByteArray.Length;
                Stream postStream = hwrequest.GetRequestStream();
                postStream.Write(postByteArray, 0, postByteArray.Length);
                postStream.Close();
            }

            // Attempt to receive the WebResponse to the WebRequest.
            using (HttpWebResponse hwresponse = (HttpWebResponse)hwrequest.GetResponse())
            {
                if (hwresponse != null)
                { // If we have valid WebResponse then read it.
                    using (StreamReader reader = new StreamReader(hwresponse.GetResponseStream()))
                    {
                        XPathDocument doc = new XPathDocument(reader);
                        XPathNavigator xml = doc.CreateNavigator();
                        responseData = xml.ToString().Trim();

                        reader.Close();
                    }
                }

                hwresponse.Close();

            }


        }
        catch (Exception e)
        {
            responseData = "An error occurred: " + e.Message;
        }



        return responseData;
    }

Может кто-нибудь увидеть, где я иду не так, очевидно, ему не нравится XML, но я не уверен, почему или как обойти это

...