"远程服务器返回错误:(417)期望失败."

Ate*_*nış 6 .net c# wcf firewall

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

远程服务器返回错误:(417)期望失败.

我认为它是由办公室网络中的防火墙造成的..用Google搜索过多,尝试了很多,但问题仍然在这里.

System.Net.ServicePointManager.Expect100Continue = false;
Run Code Online (Sandbox Code Playgroud)

不起作用,因为.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>
Run Code Online (Sandbox Code Playgroud)

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

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

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

Nat*_* B. 1

好吧,你在这里发布了问题,Can Bilgin给出了答案。我把它贴在这里是为了那些比你有问题的人。

我认为应该可以手动添加标头...我会尝试使用操作范围...来自前面的示例:

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

因为在使用 httpclient 的 http 请求上,您可以执行类似的操作(再次来自前面的示例):

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();
Run Code Online (Sandbox Code Playgroud)