gpt4 book ai didi

c# - "The remote server returned an error: (417) Expectation Failed."

转载 作者:太空狗 更新时间:2023-10-29 21:58:44 25 4
gpt4 key购买 nike

我正在编写使用我的 wcf 服务的 Windows 8 应用程序(在 Visual Studio 2012 上)。当我在家里尝试时它运行良好,因此它可以连接到 wcf。但是当我在我的办公室尝试时,它无法连接到 wcf 并返回错误:

The remote server returned an error: (417) Expectation Failed.

我认为它是由办公室网络中的防火墙引起的。谷歌搜索太多,尝试了很多,但问题仍然存在。

System.Net.ServicePointManager.Expect100Continue = false;

不起作用,因为 .Net Framework 4.5 没有 ServicePointManager 类,但 msdn 说 .Net 4.5 上有 ServicePointManager。 http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.expect100continue.aspx

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

不能尝试在 web.config 或 app.config 上写入,因为 win8 应用程序没有这些文件..

有些人将上面的代码写到VS 2012的devenv.exe.config文件中。我试过了,但没有任何改变。

http://www.jlpaonline.com/?p=176

最佳答案

那么,您发布了问题 here , 和 Can Bilgin给出了答案。我将它发布在这里,供那些比你有问题的人使用。

I think it should be possible to add the header manually... I would give it a go with the operationscope... from an earlier example:

Task<GetADGroupMemberResponse> AccountManagement.GetADGroupMemberAsync(GetADGroupMemberRequest request)
{
// CB: Creating the OperationContext
using (var scope = new OperationContextScope(this.InnerChannel))
{
// CB: Creating and Adding the request header
var header = MessageHeader.CreateHeader("Server", "http://schemas.microsoft.com/2008/1/ActiveDirectory/CustomActions", request.Server);
OperationContext.Current.OutgoingMessageHeaders.Add(header);

return base.Channel.GetADGroupMemberAsync(request);
}
}

cause on the http requests with the httpclient you can do something like (again from an earlier example):

var httpClient = new HttpClient(); 
var httpContent = new HttpRequestMessage(HttpMethod.Post, "http://app.proceso.com.mx/win8/login");

// NOTE: Your server was returning 417 Expectation failed,
// this is set so the request client doesn't expect 100 and continue.
httpContent.Headers.ExpectContinue = false;

var values = new List<KeyValuePair<string, string>>();
values.Add(new KeyValuePair<string, string>("user", "******"));
values.Add(new KeyValuePair<string, string>("pass", "******"));

httpContent.Content = new FormUrlEncodedContent(values);

HttpResponseMessage response = await httpClient.SendAsync(httpContent);

// here is the hash as string
var result = await response.Content.ReadAsStringAsync();

关于c# - "The remote server returned an error: (417) Expectation Failed.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12703265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com