【问题标题】:WCF fails to deserialize correct(?) response message security headers (Security header is empty)WCF 无法反序列化正确的(?)响应消息安全标头(安全标头为空)
【发布时间】:2011-06-05 18:44:59
【问题描述】:

我正在使用 WCF 客户端与 OC4J Web 服务进行通信。客户端配置如下:

        <basicHttpBinding>
<binding name="MyBinding">
 <security mode="TransportWithMessageCredential">
  <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
  <message clientCredentialType="UserName" algorithmSuite="Default"/>
 </security>
</binding>

我的客户端代码如下:

    ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();

    string username = ConfigurationManager.AppSettings["user"];
    string password = ConfigurationManager.AppSettings["pass"];

    // client instance maken
    WebserviceClient client = new WebserviceClient();

    client.Endpoint.Binding = new BasicHttpBinding("MyBinding");

    // credentials toevoegen
    client.ClientCredentials.UserName.UserName = username;
    client.ClientCredentials.UserName.Password = password;

    //uitvoeren request
    var response = client.Ping();

我已更改 CertificatePolicy 以接受所有证书,因为我需要在客户端和服务器之间插入 Charles(ssl 代理)以拦截通过网络发送的实际 Xml。

我的请求如下:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
 <u:Timestamp u:Id="_0">
  <u:Created>2010-04-01T09:47:01.161Z</u:Created>
  <u:Expires>2010-04-01T09:52:01.161Z</u:Expires>
 </u:Timestamp>
 <o:UsernameToken u:Id="uuid-9b39760f-d504-4e53-908d-6125a1827aea-21">
  <o:Username>user</o:Username>
  <o:Password o:Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username- token-profile-1.0#PasswordText">pass</o:Password>
 </o:UsernameToken>
</o:Security>
</s:Header>
<s:Body>
<getPrdStatus xmlns="http://mynamespace.org/wsdl">
 <request xmlns="" xmlns:a="http://mynamespace.org/wsdl"  xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <a:IsgrStsRequestTypeUser>
   <a:prdCode>LEPTO</a:prdCode>
   <a:sequenceNumber i:nil="true" />
   <a:productionType i:nil="true" />
   <a:statusDate>2010-04-01T11:47:01.1617641+02:00</a:statusDate>
   <a:ubn>123456</a:ubn>
   <a:animalSpeciesCode>RU</a:animalSpeciesCode>
  </a:IsgrStsRequestTypeUser>
 </request>
 </getPrdStatus>
 </s:Body>
</s:Envelope>

作为回报,我收到以下回复:

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns0="http://mynamespace.org/wsdl">
<env:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" env:mustUnderstand="1" />
</env:Header>
<env:Body>
<ns0:getPrdStatusResponse>
<result>
  <ns0:IsgrStsResponseTypeUser>
  <ns0:prdCode>LEPTO</ns0:prdCode>
  <ns0:color>green</ns0:color>
  <ns0:stsCode>LEP1</ns0:stsCode>
  <ns0:sequenceNumber xsi:nil="1" />
  <ns0:productionType xsi:nil="1" />
  <ns0:IAndRCode>00</ns0:IAndRCode>
  <ns0:statusDate>2010-04-01T00:00:00.000+02:00</ns0:statusDate>
  <ns0:description>Gecertificeerd vrij</ns0:description>
  <ns0:ubn>123456</ns0:ubn>
  <ns0:animalSpeciesCode>RU</ns0:animalSpeciesCode>
  <ns0:name>gecertificeerd vrij</ns0:name>
  <ns0:ranking>17</ns0:ranking>
  </ns0:IsgrStsResponseTypeUser>
 </result>
</ns0:getPrdStatusResponse>
</env:Body>
</env:Envelope>

为什么 WCF 不能反序列化此响应标头?我收到“安全标头为空”异常:

Server stack trace: 
at System.ServiceModel.Security.ReceiveSecurityHeader.Process(TimeSpan timeout)
at     System.ServiceModel.Security.TransportSecurityProtocol.VerifyIncomingMessageCore(Message& message, TimeSpan timeout)
at System.ServiceModel.Security.TransportSecurityProtocol.VerifyIncomingMessage(Message& message, TimeSpan timeout)
at System.ServiceModel.Security.SecurityProtocol.VerifyIncomingMessage(Message& message, TimeSpan timeout, SecurityProtocolCorrelationState[] correlationStates)
at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.ProcessReply(Message reply, SecurityProtocolCorrelationState correlationState, TimeSpan timeout)
at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

谁知道这里发生了什么?我已经尝试过Rick Strahl's suggestion 并从请求标头中删除了时间戳。非常感谢任何帮助!

【问题讨论】:

    标签: wcf soap ws-security


    【解决方案1】:

    以下知识库文章似乎解决了我的问题:http://support.microsoft.com/kb/971493/

    尚未能够下载修复程序,因为似乎没有可用的下载链接...将保持此线程更新。

    【讨论】:

      【解决方案2】:

      不知道您的具体问题是否也包括在内,但有quite some options discussed in this thread

      【讨论】:

      • 我已经实现了自定义绑定,但仍然没有积极的结果。奇怪的是,WSE 毫无问题地使用这项服务。不幸的是,我不能在这个项目中使用 WSE...
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-02
      • 1970-01-01
      • 2017-08-23
      • 2014-06-23
      • 1970-01-01
      • 1970-01-01
      • 2010-12-30
      相关资源
      最近更新 更多