简体   繁体   English

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

[英]How to disable Expect:100-Continue when using WCF in Windows Store App

I need to get rid of the Expect: 100-Continue header in HTTP message, when communicating with WebService using WCF in Windows Store App. 在Windows Store App中使用WCF与WebService通信时,我需要摆脱HTTP消息中的Expect: 100-Continue标头。 I have found a lot of solutions, but none of them is possible in Windows 8: 我找到了很多解决方案,但在Windows 8中没有一个是可能的:

  1. ServicePoint.Expect100Continue = false; doesn't exist in Store App any more (No SericePoint or ServicePointManager class), 在Store App中不再存在(No SericePointServicePointManager类),
  2. I cannot change configuration in web.config file, because it doesn't exist in Store App, 我无法更改web.config文件中的配置,因为它在Store App中不存在,
  3. It is possible to change the flag in HttpClient , but I cannot access it, when using WCF, 可以在HttpClient更改标志,但在使用WCF时我无法访问它,
  4. I tried to manipulate with message headers using IClientMessageInspector , but the default HTTP headers are being added later, in higher layers, so my changes will be ovverriden. 我尝试使用IClientMessageInspector处理消息头,但是稍后在较高层中添加了默认的HTTP头,因此我的更改将是ovverriden。

Does anyone have any other ideas? 有没有人有任何其他想法?

There are 2 ways to deal with this. 有两种方法可以解决这个问题。

You can turn set expect100Continue="false" in you app.config or web.config, but this will be global . 您可以在app.config或web.config中设置expect100Continue =“false”,但这将是全局的 This could be an issue if some external services prefer to use the header expect100Continue. 如果某些外部服务更喜欢使用标头expect100Continue,这可能是一个问题。 Here's how: 这是如何做:

<system.net>
     <settings>
        <servicePointManager expect100Continue="false"/>  
     </settings>
</system.net>

Or you can do it in code for a specific endpoint as follows: 或者您可以在特定端点的代码中执行此操作,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM