locked
HttpClient call to SharePoint2010 server is failing from the second request onwards in Windows Phone 8.0/8.1 RRS feed

  • Question

  • I created a PCL library for accessing a SharePoint2010 server using HttpClient. When I use this PCL in windows phone 8.0/8.1, I am getting an "404 NotFound" error from the second request onwards. The first call always works. The same PCL is working fine in iOS and Android phone.

    Also, if I use HttpWebRequest, it is working fine with all the Platforms. Can someone look into this issue?

    Below is the code:

    HttpClient client = null;
                HttpClientHandler handler = null;
                if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
                {
                    handler = new HttpClientHandler();
                    handler.Credentials = new NetworkCredential(userName, password);
                }

                if (handler != null)
                    client = new HttpClient(handler);
                else
                    client = new HttpClient();
               
                HttpResponseMessage response = await client.GetAsync(url);
                response.EnsureSuccessStatusCode();
                responseString = await response.Content.ReadAsStringAsync();

    ~Sakthivel R

    Thursday, March 3, 2016 1:06 PM

Answers

  • @Sakthivel R,

    >>The extension libraries you mentioned in your reply didn't help me, I got the same error.

    If the Windows Runtime class also does not work, maybe like this blog mentioned:

    https://blogs.msdn.microsoft.com/bclteam/2013/02/18/portable-httpclient-for-net-framework-and-windows-phone/

    Maybe you need a specific Portable library to do this. Another solution might be the HttpWebRequest.

    Anyway, since you have already select HttpWebRequest. I think this case can be closed.

    If you have any further problem or if you want some other solutions you can give the above blog a try.

    Have a nice day. :)

    Barry


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Kristin Xie Tuesday, March 15, 2016 5:42 AM
    • Marked as answer by DotNet Wang Monday, March 21, 2016 3:28 AM
    Thursday, March 10, 2016 9:56 AM

All replies

  • Hello Sakthivel R,

    >>When I use this PCL in windows phone 8.0/8.1, I am getting an "404 NotFound" error from the second request onwards.

    It seems you mentioned windows phone 8.0/8.1 so this is a Windows Phone Silverlight app or your library is actually windows runtime library?

    Although you are using HttpClient and HttpWebRequest is that all .NET library(In windows runtime there are exist HttpClient library)?

    Based on my understanding there are two possible reasons:

    1. The server done something and refuse your call.

    2. Your call is not released after you start the second call.

    To know what's happened I recommend you use Fiddler or some other similar tool to see your incoming calls from your Server. Or you can debug you app and see the network calls from your local test machine with a emulator.

    By the way, if you are actually the WP Silverlight app, then it seems some others also reproduced this issue on here :

    You may actually need this library: https://blogs.msdn.microsoft.com/bclteam/2013/02/18/portable-httpclient-for-net-framework-and-windows-phone/

    Or switch to use the HttpWebRequest as you already know.

    Best regards,

    Barry


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, March 4, 2016 2:23 AM
  • Hello,

    can I ask you about this:

    ...

    else

         client = new HttpClient();

    If your code will start again, there is on start 

         HttpClient client = null;

    Is this ok, because if you create after that new instance, on start you assign to it null.

    Regards...

    Duris_I


    • Edited by Duris_I Friday, March 4, 2016 9:56 AM
    Friday, March 4, 2016 9:55 AM
  • Thanks Barry for your response!!! The extension libraries you mentioned in your reply didn't help me, I got the same error. I assume there is no problem with the SharePoint server because the same code is working in iOS and Droid. My project deadline is not allowing me to invest more time on this, so sticking with HttpWebRequest :-)

    Thank you,

    Sakthivel R

    Tuesday, March 8, 2016 7:25 AM
  • Hi Duris_I,

    I don't think that is causing problem because this code works fine in iOS and Android. Facing problem only in Windows Phone (desktop application also works fine)

    Thanks for your response!

    ~Sakthivel R

    Tuesday, March 8, 2016 7:27 AM
  • @Sakthivel R,

    >>The extension libraries you mentioned in your reply didn't help me, I got the same error.

    If the Windows Runtime class also does not work, maybe like this blog mentioned:

    https://blogs.msdn.microsoft.com/bclteam/2013/02/18/portable-httpclient-for-net-framework-and-windows-phone/

    Maybe you need a specific Portable library to do this. Another solution might be the HttpWebRequest.

    Anyway, since you have already select HttpWebRequest. I think this case can be closed.

    If you have any further problem or if you want some other solutions you can give the above blog a try.

    Have a nice day. :)

    Barry


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Kristin Xie Tuesday, March 15, 2016 5:42 AM
    • Marked as answer by DotNet Wang Monday, March 21, 2016 3:28 AM
    Thursday, March 10, 2016 9:56 AM