简体   繁体   English

SOAP标题Action未被理解

[英]SOAP header Action was not understood

I am trying to consume a webservice in C#. 我试图在C#中使用Web服务。 Whenever i try to call the function from the web service class I am getting a "SOAP header Action was not understood".I've added web reference[not service reference] pointing the web service in my project. 每当我尝试从Web服务类调用该函数时,我得到的是“SOAP标题操作未被理解”。我已经在我的项目中添加了指向Web服务的Web引用[not service reference]。 The following steps were taken to add the web reference 采取以下步骤添加Web引用

1) right click on the project -> Add WebReference 1)右键单击项目 - >添加WebReference

when i examined the web service in web browser i found this in the header 当我在网络浏览器中检查Web服务时,我在标题中找到了这个

<wsdl:definitions name="MyService" targetNamespace="http://tempuri.org/">
    <wsp:Policy wsu:Id="WSHttpBinding_ICAIService_policy">
        <wsp:ExactlyOne><wsp:All><sp:TransportBinding>
    <wsp:Policy>

I've done the following code to call the web service functions 我已经完成了以下代码来调用Web服务功能

WebStruct webS = new WebStruct();
webS.Name = "Peter";
webS.ID = 22;

webS.Find(webS);

删除Web引用并添加服务引用。

Try to use simple service endpoint binding BasicHttpBinding. 尝试使用简单的服务端点绑定BasicHttpBinding。 This binding is compatible with .NET 2.0. 此绑定与.NET 2.0兼容。

SoapAction errors only went away when I went into the "Configure Service Reference..." properties and updated the Service Reference with these options ticked. 当我进入“配置服务引用...”属性并使用这些选项更新服务引用时,SoapAction错误才消失。

and ticked these two boxes: 并勾选这两个方框:

TICK Generate asynchronous operations TICK Always generate message contracts TICK生成异步操作TICK始终生成消息协定

Can you check with your webservice provider? 您可以咨询您的网络服务提供商吗? Seems they need some customized header information to process your request. 似乎他们需要一些自定义标头信息来处理您的请求。 Adding such headers by the service providers are very much common to increase the security. 服务提供商添加此类标头非常常见,以提高安全性。

here is some nice code too if you need it: 如果你需要它,这里也有一些不错的代码:

//Set username and password for Basic Auth
service.ClientCredentials.UserName.UserName = "usernamehere";
service.ClientCredentials.UserName.Password = "passwordhere";

//Ignore invalid SSL certs
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM