简体   繁体   English

Windows Store应用程序的ServicePoint.Expect100Continue

[英]ServicePoint.Expect100Continue for Windows Store Apps

As the title says, i need to set this flag to false for my app, like so: 如标题所示,我需要为我的应用将此标志设置为false,如下所示:

 ServicePoint.Expect100Continue = false;

However neither ServicePoint nor ServicePointManager are accessible, and i can't find another way to set this property. 但是,ServicePoint和ServicePointManager均不可访问,而且我找不到设置该属性的另一种方法。 Also, there is no app.config so setting it via configuration is also not possible. 此外,由于没有app.config,因此也无法通过配置进行设置。

If i do no set this to false, the flag is sent in the request and a CommunicationException occurs. 如果我不将其设置为false,则在请求中发送该标志,并发生CommunicationException。

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.

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. 原因是Expect100Continue属性。 If i remove it using the usual methods , it works in the console app. 如果我使用通常的方法将其删除,则它将在控制台应用程序中工作。

So, i'd like to know what the equivalent is for Windows Store apps. 因此,我想知道Windows Store应用程序的等效功能。

I ended up taking the auto-generated classes from "add service reference" and serializing them myself. 我最终从“添加服务参考”中获取了自动生成的类,并亲自对其进行了序列化。 I then use HttpClient to make my calls. 然后,我使用HttpClient进行呼叫。 It is possible to set the ExpectContinue flag there like this: 可以像下面这样设置ExpectContinue标志:

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

      ....code!
 }

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

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