如何在Windows应用商店应用中使用WCF时禁用Expect:100-Continue

Lau*_*rer 6 c# wcf

Expect: 100-Continue在Windows Store App中使用WCF与WebService进行通信时,我需要删除HTTP消息中的标头.我找到了很多解决方案,但在Windows 8中没有一个是可能的:

  1. ServicePoint.Expect100Continue = false;商店应用程序中不再存在(No SericePointServicePointManagerclass),
  2. 我无法更改web.config文件中的配置,因为它在Store App中不存在,
  3. HttpClient使用WCF时,可以更改标志,但我无法访问它,
  4. 我尝试使用消息头进行操作IClientMessageInspector,但是稍后会在更高层中添加默认的HTTP标头,因此我的更改将是ovverriden.

有没有人有任何其他想法?

Ant*_*onK 3

有两种方法可以解决这个问题。

您可以在 app.config 或 web.config 中设置 Expect100Continue="false" ,但这将是全局的。如果某些外部服务更喜欢使用 Expect100Continue 标头,这可能会成为问题。就是这样:

<system.net>
     <settings>
        <servicePointManager expect100Continue="false"/>  
     </settings>
</system.net>
Run Code Online (Sandbox Code Playgroud)

或者您可以在特定端点的代码中执行此操作,如下所示:

System.Net.ServicePoint servicePoint =
     System.Net.ServicePointManager.FindServicePoint(myWcfService.Endpoint.Address.Uri);
servicePoint.Expect100Continue = false;
// now execute some service operation 
Run Code Online (Sandbox Code Playgroud)