【发布时间】:2014-08-03 09:09:02
【问题描述】:
问题是:我需要连接到一个肥皂网络服务;由java代码生成;通过 C# 通过 MS Visual Studio 2013 使用 ASP.Net 客户端。
尝试1,通常的方法:
我使用 wsdl 添加了一个 Web 服务引用,并通过分配如下凭据:
Credentials.Username.Username = "test";
Credentials.Password.Password = "test";
执行时遇到如下异常:
The login information is missing!
尝试2:
我搜索过类似的问题,例如:
how-to-go-from-wsdl-soap-request-envelope-in-c-sharp
Dynamic-Proxy-Creation-Using-C-Emit
c# - Client to send SOAP request and received response
我选择使用 wsdl 工具生成代理类,然后添加 header 属性,但我从 Microsoft 找到了以下注释:
注意:如果 Web 服务定义了代表 SoapHeader 或 SoapUnknownHeader 类型的 SOAP 标头的成员变量,而不是从 SoapHeader 派生的类,则代理类将没有任何有关该 SOAP 标头的信息。
尝试 3: 我已经尝试在客户端 web.config 中更改服务模型:
<bindings>
<basicHttpBinding>
<binding name="CallingCardServicePortBinding">
<security mode="TransportWithMessageCredential" >
<message clientCredentialType="UserName"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
然后像第一次尝试一样添加凭据,但出现以下错误:
MustUnderstand headers:[{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}Security] are not understood
所以,现在我不知道该怎么办了! 我无法控制 Web 服务,我需要构建一个能够理解它的客户端。
请帮忙!
Soap 请求模板如下:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="...">
<soapenv:Header>
<credentials>
<userName>someUserName</userName>
<password>somePassword</password>
</credentials>
</soapenv:Header>
<soapenv:Body>
<ser:someRequest>
.......
.......
.......
</ser:someRequest>
【问题讨论】:
-
不要使用 wsdl.exe。它是旧 ASMX 技术栈的一部分。 ASMX 是一项遗留技术,不应用于新开发。 WCF 或 ASP.NET Web API 应用于 Web 服务客户端和服务器的所有新开发。一个提示:Microsoft 已停用 MSDN 上的 ASMX Forum。
标签: asp.net web-services authentication soap wsdl