2

我对 SOAP 很陌生,所以请放轻松。我正在尝试设置一个接受以下标头格式的 SOAP 服务:

<soap:Header>
   <wsse:Security>
      <wsse:UsernameToken wsu:Id='SecurityToken-securityToken'>
         <wsse:Username>Username</wsse:Username>
         <wsse:Password>Password</wsse:Password>
         <wsu:Created>Timestamp</wsu:Created>
      </wsse:UsernameToken>
   </wsse:Security>
</soap:Header>

我将此服务合并到的应用程序是一个 ASP.NET 3.5 Web 应用程序,我已经使用 WCF 设置了一个 SOAP 端点。我已经设置了一项基本服务,以确保 WCF 正常工作并且工作正常(忽略标题)。听说上面的格式遵循WS-Security所以我在web.config中添加了WSHttpBinding:

<service name="Nexternal.Service.XMLTools.VNService"
         behaviorConfiguration="VNServiceBehavior">
  <!--The first endpoint would be picked up from the confirg
  this shows how the config can be overriden with the service host-->
  <endpoint address=""
            binding="wsHttpBinding"
            contract="Nexternal.Service.XMLTools.IVNService"/>
</service>

我下载了一个测试工具(soapUI)并粘贴了带有上述标题的测试消息,它返回了 400 Bad Request 错误。

...对于它的价值,我正在使用 IIS7 运行 Visual Studio 2008。

我觉得我在绕圈子,所以任何帮助都会很棒。提前致谢。

4

1 回答 1

3

弄清楚了。我能够使用MessageContracts( http://msdn.microsoft.com/en-us/library/ms730255.aspx ) 自定义 WSDL 中生成的内容。这允许我指定标题的格式。对于包含子节点的每个节点,我创建了一个类来表示该节点并使用 .NET 的序列化工具(例如XmlElementAttributeXmlArrayAttribute等)来指定这应该如何反映在生成的WSDL. DataContract也可以使用,尽管据我了解DataContract只是用于基本格式,并且不允许您真正深入了解它的格式。

希望这可以帮助任何有类似问题的人。

如果任何对 SOAP 有更多了解的人发现了一个缺陷,请告诉我。非常感谢您的输入。

于 2010-04-07T18:41:24.103 回答