过去两周我一直试图访问第三方网络服务,现在我无可奈何地感到困惑.
因此,Web服务是在Intranet中设置的.我有URL,用户和密码来访问它.他们还向我发送了用于生成代理类的.wsdl,但每当我尝试调用函数/方法时,我都会收到错误"安全令牌无法通过身份验证或授权.".
当然,我对webservices等不太满意,但我很确定大多数设置是由代理类完成的.我在那里设置了webservice的URL,并通过凭证和自定义绑定解析了帐户信息,但是出了点问题......第三方开发人员只告诉我,验证模式是NTML Kerberos,它并没有完全帮助我在这里.我尝试将安全性中的authenticationMode设置为Kerberos,但最终只有另一个错误(未找到主体).
代理呼叫:
var binding = new CustomBinding("CrmDienstWSBinding"); //in web.config
var proxy = new CrmDienstWSClient(binding, new EndpointAddress("xxxx"));
proxy.ClientCredentials.UserName.UserName = user;
proxy.ClientCredentials.UserName.Password = pw;
var erg = proxy.erstelleAufgabe("false", erstAufg);
Run Code Online (Sandbox Code Playgroud)
代理构造函数:
public CrmDienstWSClient() {
}
public CrmDienstWSClient(string endpointConfigurationName) :
base(endpointConfigurationName) {
}
public CrmDienstWSClient(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public CrmDienstWSClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public CrmDienstWSClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress) {
}
Run Code Online (Sandbox Code Playgroud)
web.config中:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CrmDienstWSBinding">
<textMessageEncoding messageVersion="Soap12" />
<httpTransport />
</binding>
</customBinding>
</bindings>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
我知道这几行不是很多,但我不能真正发布那么多,因为web服务来自第三方.我会尝试获得解决此问题所需的任何信息..所以请帮助我〜.〜
提前致谢.
[编辑17.07.15]所以我终于得到了更多信息..
<soap:Header>
<wsse:Security soap:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-22" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>testmann@15885</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">geheim</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
Run Code Online (Sandbox Code Playgroud)
所以现在我知道Header应该是什么样的,但通常这些东西应该用.wsdl创建,所以我只需要设置我的用户名和密码,对吧?我是否必须更改wsdl生成的代码?
还有另一种使用soapUI来获取Access的方法.从来没有使用它,但我现在就看看它.
在.wsdl中,标题不完整..示例:
<operation name="erstelleAufgabe">
<soap12:operation soapAction="" />
<input>
<soap12:body use="literal" parts="erstelleAufgabe" />
<soap12:header message="tns:CrmDienstWS_erstelleAufgabe" part="IgnoreWarnings" use="literal" />
</input>
<output>
<soap12:body use="literal" />
</output>
<fault name="ServiceFault">
<soap12:fault use="literal" name="ServiceFault" namespace="" />
</fault>
</operation>
Run Code Online (Sandbox Code Playgroud)
命名空间:xmlns:soap12 ="http://schemas.xmlsoap.org/wsdl/soap12/wsdl11soap12-20060302.xsd"
xsd在标题下甚至没有这些XML元素.现在我真的很困惑.我认为服务提供商搞砸了很多时间.