我有一个控制台应用程序,只需单击写入并使用“添加服务引用”即可添加 Web 引用,然后我的 .Config 文件更改为:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="FServiceSoapBinding" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://ServiceAdd/FService" binding="basicHttpBinding"
bindingConfiguration="FServiceSoapBinding" contract="MyReference.MService_"
name="FServicePort" />
</client>
</system.serviceModel>
</configuration>
所以,一切都很好,似乎我可以成功使用该服务,但服务文档说我需要在请求的标题上设置用户名和密码,这是文档的示例:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:web="http://namespace.com/">
<soapenv:Header>
<Account>
<username>user</username>
<password>password</password>
</Account>
</soapenv:Header>
<soapenv:Body>
<web:oneofservicemethods>
<items>
<item>...</item>
</items>
</web:oneofservicemethods>
</soapenv:Body>
</soapenv:Envelope>
那么如何将用户名和密码添加到标题中?有什么建议吗?