2012-12-03 141 views
1

我想报头信息添加到我的Web服务,这是我基本的向导在Visual Studio中创建2012添加标题信息到我的Web服务引用请求

我只是点击“添加服务引用”,给我的链接VS自己创建了代码。我必须使用哪个课程来传递我的请求的标题信息?我是否必须重写VS自动创建的代码?

还要说明一点:如果你知道另一种方式来添加一个头一个Web服务,我想使用它。我不必使用automaticaly创建的代码。 (虽然使用它们很方便)。

回答

0

.Net Framework在后台自行创建并修补头文件,所以我应该做的是在web.config中添加username-password头值,而不是将其绑定到帖子本身。

<client> 
    <endpoint address="http://ServiceAdd/FService" binding="basicHttpBinding" 
    bindingConfiguration="FServiceSoapBinding" contract="MyReference.MService_" 
    name="FServicePort" > 
     <headers> 
      <Account> 
       <username>user</username> 
       <password>password</password> 
      </Account> 
     </headers> 
    </endpoint> 
</client> 
相关问题