Expect: 100-Continue在Windows Store App中使用WCF与WebService进行通信时,我需要删除HTTP消息中的标头.我找到了很多解决方案,但在Windows 8中没有一个是可能的:
ServicePoint.Expect100Continue = false;商店应用程序中不再存在(No SericePoint或ServicePointManagerclass),web.config文件中的配置,因为它在Store App中不存在,HttpClient使用WCF时,可以更改标志,但我无法访问它,IClientMessageInspector,但是稍后会在更高层中添加默认的HTTP标头,因此我的更改将是ovverriden.有没有人有任何其他想法?
有两种方法可以解决这个问题。
您可以在 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)