How to write client side for soap in c#

纵然是瞬间 提交于 2019-11-26 22:15:08

问题


I have a project file which I have tested using SOAP UI.

Now I wanted to write it's client side so by viewing this solution I have tried to do things work. But I am having a problem.

In the solution, URL and action are mentioned. I have a URL but I am not sure what is my action URL. So I put both of the same.

var _url = "http://111.111.111.1:111/HES/services/DoCommandRequest";
        var _action = "http://111.111.111.1:111/HES/services/DoCommandRequest";

 XmlDocument soapEnvelopeXml = CreateSoapEnvelope();
        HttpWebRequest webRequest = CreateWebRequest(_url, _action);
        InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);

        // begin async call to web request.
        IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);

        // suspend this thread until call is complete. You might want to
        // do something usefull here like update your UI.
        asyncResult.AsyncWaitHandle.WaitOne();

        // get the response from the completed web request.
        string soapResult;
        using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
        {
            using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
            {
                soapResult = rd.ReadToEnd();
            }
            Console.Write(soapResult);
        }

After running my code I am getting an exception at using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult)) which says

System.Net.WebException {"The remote server returned an error: (500) Internal Server Error."}

I believe that there is some problem with my action, but I am not sure.

Any help would be highly appreciated.

来源:https://stackoverflow.com/questions/55430357/how-to-write-client-side-for-soap-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!