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



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

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

最佳答案

好吧,您发布了问题hereCan 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);
    }
}


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();

10-06 10:39
查看更多