ServicePoint.Expect100Continue为Windows商店应用程序 [英] ServicePoint.Expect100Continue for Windows Store Apps

查看:673
本文介绍了ServicePoint.Expect100Continue为Windows商店应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说,我需要设置该标志为false,我的应用程序,像这样:

As the title says, i need to set this flag to false for my app, like so:

 ServicePoint.Expect100Continue = false;



不过既不的ServicePoint也不ServicePointManager的访问,我无法找到另一种方式来设置该属性。此外,没有通过的app.config配置,设定同样是不可能的。

However neither ServicePoint nor ServicePointManager are accessible, and i can't find another way to set this property. Also, there is no app.config so setting it via configuration is also not possible.

如果我没有做这个设置为false,该标志在请求发送,发生的CommunicationException。

If i do no set this to false, the flag is sent in the request and a CommunicationException occurs.

我不能改变服务器代码,我是唯一的服务器数据的消费者。

I cannot change server code, i am only a consumer of server data.

该服务中添加了添加服务引用对话框。在任何方法调用的结果:

The service is added with the "Add Service Reference" dialog. Any method call results in:

The underlying connection was closed: An unexpected error occurred on a receive.

当我调用相同的服务,加入添加服务引用从控制台应用程序,有同样的错误。其原因是Expect100Continue属性。如果我删除它的使用常用方法的,它工作在控制台应用程序。

When i call the same service, added with "Add Service Reference" from a console application, there is the same error. The reason is the Expect100Continue Attribute. If i remove it using the usual methods, it works in the console app.

所以,我想要知道相当于是为Windows Store应用程序。

So, i'd like to know what the equivalent is for Windows Store apps.

推荐答案

我结束了从添加服务引用走的是自动生成的类和序列化他们自己。然后我用的HttpClient让我的电话。它可以有设置E​​xpectContinue标志是这样的:

I ended up taking the auto-generated classes from "add service reference" and serializing them myself. I then use HttpClient to make my calls. It is possible to set the ExpectContinue flag there like this:

 using (HttpClient client = new HttpClient())
 {
      client.DefaultRequestHeaders.ExpectContinue = false;

      ....code!
 }

这篇关于ServicePoint.Expect100Continue为Windows商店应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆