Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

i'm writing windows 8 app.(on Visiual Studio 2012) which uses my wcf service. It works well when i try at my home, so it can connect to the wcf. But when i tried at my office, it cannot connect to wcf and returns error :

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

I think its causing by firewall in the office network.. Googled too much, tried a lot of however the problem still here.

System.Net.ServicePointManager.Expect100Continue = false;

Doesn't work because .Net Framework 4.5 has not ServicePointManager Class but msdn says there is ServicePointManager on .Net 4.5.. http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.expect100continue.aspx

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

Cannot try this to write on web.config or app.config because win8 app has not these files..

some people wrote above code to devenv.exe.config file of VS 2012. I tried it but nothing changed.

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

like image 401
Ateş Danış Avatar asked Oct 03 '12 06:10

Ateş Danış


1 Answers

Well, you posted the question here, and Can Bilgin gave an answer. I post it here for those who have the problem than you.

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();
like image 150
Nate B. Avatar answered Sep 28 '22 06:09

Nate B.