【问题标题】:The security token could not be authenticated or authorized (.net, soap1.2)无法对安全令牌进行身份验证或授权(.net、soap1.2)
【发布时间】:2015-10-02 22:58:35
【问题描述】:

过去两周我一直在尝试访问第三方网络服务,现在我感到非常困惑。

所以网络服务是在内联网中设置的。我有访问它的 URL、用户和密码。他们还向我发送了我用来生成代理类的 .wsdl,但每当我尝试调用函数/方法时,我都会收到错误消息“无法验证或授权安全令牌。”。

当然,我不太擅长网络服务等,但我很确定大部分设置都是由代理类进行的。我在那里设置了 Web 服务的 URL,并通过凭据和自定义绑定解析了帐户信息,但是出了点问题...... 第 3 方开发人员只告诉我身份验证模式是 NTML Kerberos,这在这里对我没有帮助。我尝试将安全身份验证模式设置为 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>

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

提前致谢。

[EDIT 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 的标题下甚至没有这些 XML 元素。现在我真的很困惑。我认为服务提供商搞砸了。

【问题讨论】:

    标签: .net soap proxy


    【解决方案1】:

    最后我们亲爱的服务商忘记激活密码了……

    【讨论】:

      【解决方案2】:

      不确定这是否可行,但您可以尝试一下。

       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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-24
        • 1970-01-01
        • 2013-02-12
        • 2017-07-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多