安全令牌无法通过身份验证或授权(.net,soap1.2)

时间:2015-07-14 10:43:19

标签: .net soap proxy

过去两周我一直试图访问第三方网络服务,现在我无可奈何地感到困惑。

因此,在Intranet中设置了Web服务。我有URL,用户和密码来访问它。他们还向我发送了用于生成代理类的.wsdl,但每当我尝试调用函数/方法时,我都会收到错误&#34;安全令牌无法通过身份验证或授权。&#34;。< / p>

当然,我对网络服务并不是很好,但我确信大多数设置都是由代理类完成的。我在那里设置了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);

代理构造函数:

    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>

我知道这几行不是很多,但我不能发布那么多,因为网络服务来自第三方。我会尝试获得解决此问题所需的任何信息..所以请帮助我〜。

提前致谢。

[编辑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中,标题不完整..例如:

<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 =&#34; HTTP://schemas.xmlsoap.org/wsdl/soap12/wsdl11soap12-20060302.xsd"

xsd甚至在标题下都没有这些XML元素。现在我真的很困惑。我认为服务提供商搞砸了很长时间。

2 个答案:

答案 0 :(得分:6)

最后,我们亲爱的服务提供商忘记激活密码......

答案 1 :(得分:3)

不确定这是否有效,但你可以尝试一下。

 UsernameToken token = new UsernameToken(username, password, PasswordOption.SendHashed);
 proxy.RequestSoapContext.Security.Tokens.Add(token);

 var result = proxy.MethodCall();

您可以在此处获取更多信息:

MSDN - WS-Security Authentication

MSDN - UsernameToken class