无法对安全令牌进行身份验证或授权(.net、soap1.2)
The security token could not be authenticated or authorized (.net, soap1.2)
过去两周我一直在尝试访问 thirdparty-webservice,现在我感到非常困惑。
这样webservice就设置在内网了。我有 URL、用户和密码来访问它。他们还向我发送了我用来生成 proxy-class 的 .wsdl,但每当我尝试调用 functions/methods 时,我都会收到错误 "The security token could not be authenticated or authorized.".
当然,我不太擅长网络服务等,但我很确定大部分设置都是由 proxy-class 完成的。我在那里设置了网络服务的 URL 并通过凭据和自定义绑定解析帐户信息,但是出了点问题......
第 3 方开发人员只告诉我身份验证模式是 NTML Kerberos,这对我没有帮助。我尝试将安全中的 authenticationMode 设置为 Kerberos,但最终出现另一个错误(未找到主体)。
proxy-call:
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);
proxy-constructors:
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) {
}
web.config:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CrmDienstWSBinding">
<textMessageEncoding messageVersion="Soap12" />
<httpTransport />
</binding>
</customBinding>
</bindings>
</system.serviceModel>
我知道这几行不是很值得去,但我真的 post 不能那么多,因为网络服务来自第三方。我会尝试获取解决此问题所需的任何信息.. 所以请帮助我 ~.~
提前致谢。
[编辑 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>
所以现在我知道 Header 应该是什么样子了,但通常这些东西无论如何都应该用 .wsdl 创建,这样我只需要设置我的用户名和密码,对吧?我是否必须更改 wsdl 生成的代码?
还有一种方法是使用soapUI获取Access。以前从未使用过它,但我现在就看一下。
在 .wsdl 中 Header 不完整.. 示例:
<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>
命名空间:
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/wsdl11soap12-20060302.xsd"
xsd连header下的这种XML-elements都没有。现在我真的很困惑。我认为 service-provider 把时间搞砸了。
不确定这是否有效,但您可以试一试。
UsernameToken token = new UsernameToken(username, password, PasswordOption.SendHashed);
proxy.RequestSoapContext.Security.Tokens.Add(token);
var result = proxy.MethodCall();
您可以在此处获取更多信息:
最后我们亲爱的服务商忘了激活密码...
过去两周我一直在尝试访问 thirdparty-webservice,现在我感到非常困惑。
这样webservice就设置在内网了。我有 URL、用户和密码来访问它。他们还向我发送了我用来生成 proxy-class 的 .wsdl,但每当我尝试调用 functions/methods 时,我都会收到错误 "The security token could not be authenticated or authorized.".
当然,我不太擅长网络服务等,但我很确定大部分设置都是由 proxy-class 完成的。我在那里设置了网络服务的 URL 并通过凭据和自定义绑定解析帐户信息,但是出了点问题...... 第 3 方开发人员只告诉我身份验证模式是 NTML Kerberos,这对我没有帮助。我尝试将安全中的 authenticationMode 设置为 Kerberos,但最终出现另一个错误(未找到主体)。
proxy-call:
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);
proxy-constructors:
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) {
}
web.config:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CrmDienstWSBinding">
<textMessageEncoding messageVersion="Soap12" />
<httpTransport />
</binding>
</customBinding>
</bindings>
</system.serviceModel>
我知道这几行不是很值得去,但我真的 post 不能那么多,因为网络服务来自第三方。我会尝试获取解决此问题所需的任何信息.. 所以请帮助我 ~.~
提前致谢。
[编辑 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>
所以现在我知道 Header 应该是什么样子了,但通常这些东西无论如何都应该用 .wsdl 创建,这样我只需要设置我的用户名和密码,对吧?我是否必须更改 wsdl 生成的代码?
还有一种方法是使用soapUI获取Access。以前从未使用过它,但我现在就看一下。
在 .wsdl 中 Header 不完整.. 示例:
<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>
命名空间: xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/wsdl11soap12-20060302.xsd"
xsd连header下的这种XML-elements都没有。现在我真的很困惑。我认为 service-provider 把时间搞砸了。
不确定这是否有效,但您可以试一试。
UsernameToken token = new UsernameToken(username, password, PasswordOption.SendHashed);
proxy.RequestSoapContext.Security.Tokens.Add(token);
var result = proxy.MethodCall();
您可以在此处获取更多信息:
最后我们亲爱的服务商忘了激活密码...