c#soap结果错误处理身份验证

c#soap结果错误处理身份验证,c#,web-services,authentication,soap,C#,Web Services,Authentication,Soap,我正在做一个C#客户端调用wsdl Web服务。 我添加了一个带有给定链接的服务引用,生成了所有必要的对象 我的问题是身份验证。 我尝试使用SoapUI并使用此标题: <soapenv:Header> <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" x

我正在做一个C#客户端调用wsdl Web服务。 我添加了一个带有给定链接的服务引用,生成了所有必要的对象

我的问题是身份验证。 我尝试使用SoapUI并使用此标题:

<soapenv:Header>
  <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
     <wsse:UsernameToken wsu:Id="UsernameToken-F56DE979FFAADAB54F143496748776515">
        <wsse:Username>USER</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>
        <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">iPHOFi2DmB/eL9K6k8NmoQ==</wsse:Nonce>
        <wsu:Created>2015-06-22T10:04:47.765Z</wsu:Created>
     </wsse:UsernameToken>
  </wsse:Security>

我做错了什么?我解决了!这基本上是一个身份验证问题

我更改了配置:

<bindings>
  <basicHttpBinding>
    <binding name="gblDHLExpressTrackSandpit">
      <security mode="TransportWithMessageCredential">            
        <message clientCredentialType="UserName" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="https://wsb.dhl.com:443/sndpt/gblDHLExpressTrack"
    binding="basicHttpBinding" bindingConfiguration="gblDHLExpressTrackSandpit"
    contract="DHL_WS.gblDHLExpressTrackSandpit" name="gblDHLExpressTrackSandpit1" >
    <headers>
      <HeaderName>Value</HeaderName>
    </headers>
  </endpoint>
</client>

价值
并强制不包括时间戳

 System.ServiceModel.Channels.BindingElementCollection elements = client.Endpoint.Binding.CreateBindingElements();
        elements.Find<System.ServiceModel.Channels.SecurityBindingElement>().IncludeTimestamp = false;
        client.Endpoint.Binding = new System.ServiceModel.Channels.CustomBinding(elements);  
System.ServiceModel.Channels.BindingElementCollection-elements=client.Endpoint.Binding.CreateBindingElements();
elements.Find().IncludeTimestamp=false;
client.Endpoint.Binding=new System.ServiceModel.Channels.CustomBinding(元素);
当然,我通过了客户端凭据


希望它能帮助某些人:)

我建议您使用Fiddler检查应用程序与web服务器交换的HTTPS流量。我假设当web服务客户机期望以其他编码格式响应时,web服务器正在以纯HTML格式返回错误消息。
<bindings>
  <basicHttpBinding>
    <binding name="gblDHLExpressTrackSandpit">
      <security mode="TransportWithMessageCredential">            
        <message clientCredentialType="UserName" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="https://wsb.dhl.com:443/sndpt/gblDHLExpressTrack"
    binding="basicHttpBinding" bindingConfiguration="gblDHLExpressTrackSandpit"
    contract="DHL_WS.gblDHLExpressTrackSandpit" name="gblDHLExpressTrackSandpit1" >
    <headers>
      <HeaderName>Value</HeaderName>
    </headers>
  </endpoint>
</client>
 System.ServiceModel.Channels.BindingElementCollection elements = client.Endpoint.Binding.CreateBindingElements();
        elements.Find<System.ServiceModel.Channels.SecurityBindingElement>().IncludeTimestamp = false;
        client.Endpoint.Binding = new System.ServiceModel.Channels.CustomBinding(elements);