ServicePoint.Expect100Continue for Windows Store Apps

拟墨画扇 提交于 2019-12-22 18:20:46

问题


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

 ServicePoint.Expect100Continue = false;

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.

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.

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.

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


回答1:


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!
 }


来源:https://stackoverflow.com/questions/12799196/servicepoint-expect100continue-for-windows-store-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!