如何在C#中为Soap编写客户端 [英] How to write client side for soap in c#

查看:107
本文介绍了如何在C#中为Soap编写客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用SOAP UI测试过的项目文件.

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.

在解决方案中,提到了 URL action .我有一个 URL ,但是我不确定我的 action URL 是什么.所以我把两者都放在一样的地方.

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);
        }

运行代码后,我在上使用(WebResponse webResponse = webRequest.EndGetResponse(asyncResult))出现异常,该消息表示

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

System.Net.WebException{远程服务器返回错误:(500)内部服务器错误."}

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.

任何帮助将不胜感激.

推荐答案

SOAP Action在SOAP 1.1中是必需的,但可以为空(").在此处查看评论

SOAPAction is required in SOAP 1.1 but can be empty (""). See the comment here

首先,您应该尝试使用与wsdl文件的链接来创建新的SOAP项目.之后,尝试从SOAP UI发出请求.尝试运行"doCommand"行动.看结果.比起您可以将其与应用程序的请求进行比较.您还可以使用Fiddler来分隔您的请求,并比较它们以发现差异.

First of all you should try to create new SOAP project using your link to wsdl file. After that try to do request from SOAP UI. Try to run "doCommand" action. Look at the result. Than you can compare it with request from your app. You can also use Fiddler to intersept your requests and compare them to find a difference.

这篇关于如何在C#中为Soap编写客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆