C# Lumesse Web服务和WSSE纯文本安全性问题

C# Lumesse Web服务和WSSE纯文本安全性问题,c#,web-services,soap,wse,wsse,C#,Web Services,Soap,Wse,Wsse,我们目前正在开发一个遗留项目,该项目使用Lumese提供的名为overHTTPS的SOAP web服务 这在ASP.NET应用程序中使用;最初的开发人员(早就离开了)从来没有利用提供的WSDL,而是更喜欢手动构造请求并解析响应。虽然这是完全疯狂的,但这是Lumesse的文档在使用.NET时实际推荐的,因为他们的服务使用过时的WSSE纯文本安全性 虽然我们通常不会违反规则,但我们更愿意使用内置支持来使用SOAP web服务,而不是像以前的开发人员那样滚动我们自己的解决方案 我们已经遇到了一些问题

我们目前正在开发一个遗留项目,该项目使用Lumese提供的名为overHTTPS的SOAP web服务

这在ASP.NET应用程序中使用;最初的开发人员(早就离开了)从来没有利用提供的WSDL,而是更喜欢手动构造请求并解析响应。虽然这是完全疯狂的,但这是Lumesse的文档在使用.NET时实际推荐的,因为他们的服务使用过时的WSSE纯文本安全性

虽然我们通常不会违反规则,但我们更愿意使用内置支持来使用SOAP web服务,而不是像以前的开发人员那样滚动我们自己的解决方案

我们已经遇到了一些问题,例如,无法生成临时类,我们已经对这些类进行了黑客攻击。

不幸的是,在发送成功的SOAP请求时,我们现在陷入了困境

发出请求时引发的异常是:

通信对象System.ServiceModel.Channels.ServiceChannel无法用于通信,因为它处于故障状态。

深入挖掘,实际反应如下:

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
  <env:Header /> 
    <env:Body>
      <env:Fault xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
        <faultcode xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">wsse:FailedCheck</faultcode> 
        <faultstring>Expired message.</faultstring> 
      </env:Fault>
   </env:Body>
</env:Envelope>
Lumese期望的请求示例,摘自先前开发人员自行推出的解决方案-按预期工作:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.mrted.com/">
    <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-11">
                <wsse:Username>xxxx</wsse:Username>
                <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">
                    xxxx
                </wsse:Password> 
                <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">5Xhsv3Yp2l1xGpL3pNYy6A==
                </wsse:Nonce>
                <wsu:Created>2012-06-22T09:07:26.631Z</wsu:Created>
            </wsse:UsernameToken>
        </wsse:Security>
    </soapenv:Header>
    <soapenv:Body>
        <getAdvertisements xmlns="http://ws.mrted.com/">
            <firstResult>0</firstResult>
            <maxResults>0</maxResults>
        </getAdvertisements>
    </soapenv:Body>
</soapenv:Envelope>

xxxx
xxxx
5Xhsv3Yp2l1xGpL3pNYy6A==
2012-06-22T09:07:26.631Z
0
0
我们当前发送的请求示例:

<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>
        <ActivityId CorrelationId="d309ce44-ed91-4314-87ee-e3abee4f531e" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">dd9a8c26-e673-464d-87e4-5cb8b76989c3</ActivityId>
        <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>2014-09-30T16:15:47.426Z</u:Created>
                <u:Expires>2014-09-30T16:20:47.426Z</u:Expires>
            </u:Timestamp>
            <o:UsernameToken u:Id="uuid-c3275c63-6d98-4ae3-a7a7-afe314d23d6c-3">
                <o:Username>xxxx</o:Username>
                <o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxxx</o:Password>
            </o:UsernameToken>
        </o:Security>
    </s:Header>
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <getAdvertisements xmlns="http://ws.mrted.com/">
            <firstResult>0</firstResult>
            <maxResults>0</maxResults>
        </getAdvertisements>
    </s:Body>
</s:Envelope>

配置示例:

<customBinding>
  <binding name="MyBinding">
    <security authenticationMode="UserNameOverTransport" includeTimestamp="false" />
    <textMessageEncoding messageVersion="Soap11" />
    <httpsTransport maxReceivedMessageSize="26214400" />
  </binding>
</customBinding>

然后,只需按原样调用该服务,传递凭据(您可能会将这些凭据存储在web.config中,与上述内容一起,但如果我知道怎么做,我现在就完蛋了)

使用(lumesessoaptest.foadverd.foadverwebserviceclient client=new lumesessoaptest.foadverd.foadverwebserviceclient())
{
client.ClientCredentials.UserName.UserName=“xxxx”;
client.ClientCredentials.UserName.Password=“xxxx”;
foreach(varad-in-response.advertisementResult.adverties)
{
@广告职位
}
}


再次感谢。

我也在使用相同的api,并且遇到了相同的问题。如果您向下滚动到本文底部:Scott Hanselman通过代码而不是通过配置删除时间戳。

我在WSDL中没有看到安全信息,您确定这是正确的URL吗?WSDL应该有一个or(对于ws-*)。另外,在您的自传示例中,结尾的getAdvertisions标记定义为>,第二个结尾括号是否是打字错误?另外,您的第二个示例有一个AcctivityId节点,而您的自滚示例没有。这当然是一个愚蠢的问题-我想这将是一个相当大的问题?更新了自滚示例请求XML。我刚刚尝试在没有ActivityId节点的情况下手动将SOAP XML推送到Lumesse,这不会影响结果('wsse:FailedCheck')——当然,以后可能会这样!更新-刚刚尝试在UsernameToken节点中输入Nonce和已创建的节点。没有乐趣,同样的错误。丢失的Nonce元素确实会导致问题,一开始我没有注意到。不幸的是,向其中添加Nonce并不像更改设置那么简单。您将需要使用自定义绑定,并且可能必须手动构建soap数据包。至少这是我知道的唯一方法。你可以在这里和这里找到更多信息。希望这能解决你的问题。是的,这很奇怪。。。如果您通过添加服务引用导入WSDL,它会将其设置为基本绑定,这将永远不会与WSSE或WS-*一起工作。据我所见,您需要手动创建数据包,这很不幸。另外,从您的帖子中,我假设您了解SoapUI,如果不了解,请了解。另一个很好的工具是小提琴。尽管Fiddler更适用于HTTP请求,但它可以派上用场。
<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">
        <o:UsernameToken u:Id="UsernameToken-11">
        <o:Username>xxx</o:Username>
        <o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxx
        </o:Password>
        <o:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">
          5Xhsv3Yp2l1xGpL3pNYy6A==
        </o:Nonce>
        <o:Created>2012-06-22T09:07:26.631Z</o:Created>
      </o:UsernameToken>
    </o:Security>
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <getAdvertisements xmlns="http://ws.mrted.com/"><firstResult>0</firstResult><maxResults>10</maxResults>
    </getAdvertisements>
   </s:Body>
</s:Envelope>
<customBinding>
  <binding name="MyBinding">
    <security authenticationMode="UserNameOverTransport" includeTimestamp="false" />
    <textMessageEncoding messageVersion="Soap11" />
    <httpsTransport maxReceivedMessageSize="26214400" />
  </binding>
</customBinding>
using (LumesseSoapTest.FoAdvert.FoAdvertWebServiceClient client = new LumesseSoapTest.FoAdvert.FoAdvertWebServiceClient())
{
  client.ClientCredentials.UserName.UserName = "xxxx";

  client.ClientCredentials.UserName.Password = "xxxx";

  foreach (var ad in response.advertisementResult.advertisements)
  {
    @ad.jobTitle <br />
  }