我有一个控制台应用程序,我只是添加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>
所以,我怎么能在头部添加用户名和密码? 什么建议吗?