且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何发送/使用C#接收SOAP请求和响应?

更新时间:2022-03-15 06:23:19

的URL是不同的。


  • HTTP://localhost/AccountSvc/DataInquiry.asmx

  • http://localhost/AccountSvc/DataInquiry.asmx

VS


  • /acctinqsvc/portfolioinquiry.asmx

  • /acctinqsvc/portfolioinquiry.asmx

先解决这个问题,因为如果Web服务器无法解析您试图张贴到URL,你甚至不会。开始来处理您的请求所描述的动作

Resolve this issue first, as if the web server cannot resolve the URL you are attempting to POST to, you won't even begin to process the actions described by your request.

您应该只需要创建的WebRequest到ASMX根URL,例如: HTTP:/ /localhost/AccountSvc/DataInquiry.asmx ,并指定SOAPAction头所需的方法/操作。

You should only need to create the WebRequest to the ASMX root URL, ie: http://localhost/AccountSvc/DataInquiry.asmx, and specify the desired method/operation in the SOAPAction header.

的SOAPAction头值不同


  • HTTP://localhost/AccountSvc/DataInquiry.asmx/ +方法名

  • http://localhost/AccountSvc/DataInquiry.asmx/ + methodName

VS


  • http://tempuri.org/GetMyName

  • http://tempuri.org/GetMyName

您应该可以通过将正确的ASMX URL和追加,以确定正确的SOAPAction ?WSDL

You should be able to determine the correct SOAPAction by going to the correct ASMX URL and appending ?wsdl

应该有<肥皂:运转> 下方标记< WSDL:运转> 标签,你正试图操作相匹配执行,这似乎是 GetMyName

There should be a <soap:operation> tag underneath the <wsdl:operation> tag that matches the operation you are attempting to execute, which appears to be GetMyName.

有在包括请求主体没有XML声明您的SOAP XML。

您指定文本/ XML 在你的HttpRequest没有的字符集的ContentType 。也许这些默认为 US-ASCII ,但没有告诉,如果你没有指定他们!

You specify text/xml in the ContentType of your HttpRequest and no charset. Perhaps these default to us-ascii, but there's no telling if you aren't specifying them!

soapUI的创建的XML包括XML声明,指定UTF-8,这也符合提供HTTP请求的Content-Type这是一个编码:文本/ XML;字符集= UTF-8

The SoapUI created XML includes an XML declaration that specifies an encoding of utf-8, which also matches the Content-Type provided to the HTTP request which is: text/xml; charset=utf-8

希望帮助!