小编use*_*857的帖子

在C#中为Web服务调用添加自定义SOAPHeader

我想在调用Web服务之前在c#中添加自定义soap头信息.我正在使用SOAP Header类来完成这项工作.我可以部分地这样做但不完全按我需要的方式完成.这是我需要肥皂头看起来像

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Header>
      <Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <UsernameToken>
         <Username>USERID</Username>
         <Password>PASSWORD</Password>
        </UsernameToken>    
      </Security>
   </soap:Header>
   <soap:Body>
   ...
Run Code Online (Sandbox Code Playgroud)

我可以添加soap header如下

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Header>
      <UsernameToken xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <Username>UserID</Username>
         <Password>Test</Password>
      </UsernameToken>
   </soap:Header>
   <soap:Body>
Run Code Online (Sandbox Code Playgroud)

我无法做的是添加包含"UsernameToken"的"Security"元素,如第一个示例中所示.任何帮助,将不胜感激.

c# soapheader

10
推荐指数
1
解决办法
3万
查看次数

标签 统计

c# ×1

soapheader ×1