locked
PostAsJsonAsync no packet sent

    Question

  • Hello,

    I'm working on a metroUI application which has to contact a webservice on a server. Here is the code :

                    

                    BDDApplication bdd;
    
                    string adresseWebService = "http://172.16.1.126:20000/";
    
                    HttpClientHandler handler = new HttpClientHandler()
                    {
                        UseDefaultCredentials = true
                    };
                    HttpClient client = new HttpClient(handler);
                    client.Timeout = TimeSpan.FromMinutes(20);
    
                    client.MaxResponseContentBufferSize = 2147483647;
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    
                    try {
    
                    //operations on bddapplication
    
                    HttpResponseMessage responseUpload = client.PostAsJsonAsync<BDDApplication>(adresseWebService + "api/bddapplication/", bdd).Result;
    
                    }
    
                    catch (AggregateException exception)
                    {
                        tasksource.SetResult("Erreur lors de l'envoi des données.");
                        return tasksource.Task.Result;
                    }

    This works great when the application and the server are on the same network. However, when the application has to use a VPN to contact the server, wireshark shows that no frames were sent.

    The following error is thrown (when using the VPN only) :

    Interception de System.AggregateException
      HResult=-2146233088
      Message=One or more errors occurred.
      Source=mscorlib
      StackTrace:
           at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
           at AlsaceLait.BDD.<SynchronisationBDD>d__6b.MoveNext() in c:\Users\jc.marquet\Documents\Alsace Lait\AlsaceLait\AlsaceLait\AlsaceLait\Class + ressourceXaml\BDD.cs:line 125
      InnerException: System.Net.Http.HttpRequestException
           HResult=-2146233088
           Message=An error occurred while sending the request.
           InnerException: System.Net.WebException
                HResult=-2146233079
                Message=Unable to connect to the remote server
                Source=System
                StackTrace:
                     at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
                     at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
                InnerException: System.Net.Sockets.SocketException
                     HResult=-2147467259
                     Message=Une tentative d’accès à un socket de manière interdite par ses autorisations d’accès a été tentée 172.16.1.126:20000
                     Source=System
                     ErrorCode=10013
                     NativeErrorCode=10013
                     StackTrace:
                          at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
                          at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
                     InnerException: 

    Since I've found no similar case on the net any help is welcome :) Anyway thanx for reading.

    EDIT : Some additional information

    The specified adress can be accessed with a browser and this works without any issue whether we are using a VPN or not. The application can perfectly connect without the VPN. The only case where there is a problem is when we try to connect the application with the VPN in which case we have the error given above.

    I already have this capabilities enabled : 
      <Capabilities>
        <Capability Name="enterpriseAuthentication" />
        <Capability Name="internetClient" />
        <Capability Name="privateNetworkClientServer" />
        <Capability Name="internetClientServer" />
      </Capabilities>





    Tuesday, May 27, 2014 7:44 AM

Answers

  • Looks like you are getting back an error 10013 during the Connect call from winsock which means: WSAEACCES: "An attempt was made to access a socket in a way forbidden by its access permissions.". Since Connect call fails during the connection attempt itself, you don't see any TCP-SYN packets.

    Although, it is weird to see that you already have the Private Networks capability included and are still seeing that error. Are you sure that you are not trying to "loopback" to the same machine and confirm that your client side code where this HttpClient functionality is running has the right manifest declarations as above? When are you seeing that error? When debugging from Visual Studio or without debugging?


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    • Marked as answer by Enro67 Wednesday, May 28, 2014 12:48 PM
    Tuesday, May 27, 2014 11:04 PM
    Moderator
  • The customer found the solution : 

    https://supportcenter.checkpoint.com/supportcenter/portal?eventSubmit_doGoviewsolutiondetails=&solutionid=sk92881&js_peid=P-114a7ba5fd7-10001&partition=General&product=Endpoint

    This had nothing to do with the app or the capabilities (not directly at least) but was caused by an incompatibility with the VPN.

    Prashant H Phadke thank you for your time. I mark your answer cause it should solve this issue in most cases.

    • Marked as answer by Enro67 Wednesday, May 28, 2014 12:48 PM
    • Edited by Enro67 Wednesday, May 28, 2014 2:01 PM
    Wednesday, May 28, 2014 12:48 PM

All replies

  • Looks like you are getting back an error 10013 during the Connect call from winsock which means: WSAEACCES: "An attempt was made to access a socket in a way forbidden by its access permissions.". Since Connect call fails during the connection attempt itself, you don't see any TCP-SYN packets.

    Although, it is weird to see that you already have the Private Networks capability included and are still seeing that error. Are you sure that you are not trying to "loopback" to the same machine and confirm that your client side code where this HttpClient functionality is running has the right manifest declarations as above? When are you seeing that error? When debugging from Visual Studio or without debugging?


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    • Marked as answer by Enro67 Wednesday, May 28, 2014 12:48 PM
    Tuesday, May 27, 2014 11:04 PM
    Moderator
  • Thank you for your answer.

    The error is thrown at the execution of this line (debugging or not) :

    HttpResponseMessage responseUpload = client.PostAsJsonAsync<BDDApplication>(adresseWebService + "api/bddapplication/", bdd).Result;

    I also tried with GetAsync and the error is the same.

    Yes I confirm that the address IP isn't mine. It is the one of our customer's server. From a browser the correct JSON is returned and I don't have a webservice turning on my machine so no mistaking that.

    The capabilities above are copy/paste from the XML manifest (application client side).

    It reminds me that I forgot to mention that this application is running on two different clients infrastructure. On one it works great (VPN or not, browser or application, ...) and not on the other one.

    The customer assures us the port is open on the VPN and since this error occurs when the capabilities are not set correctly I looked this way first.

    I will try to see what is the IP address we get from the VPN compared to the one the webservice is on. From what you said I guess it could provoke some kind of problem.

    EDIT : the IP address are differents :

    - the servers are on 172.16.1.X;

    - the rerouting by the VPN are on 192.168.255.X.

    I saw that on Visual Studio 2013 the capabilites management could be a little different. Does it worth a try ? I mean building the app with VS2013.



    • Edited by Enro67 Wednesday, May 28, 2014 9:19 AM
    Wednesday, May 28, 2014 7:33 AM
  • The customer found the solution : 

    https://supportcenter.checkpoint.com/supportcenter/portal?eventSubmit_doGoviewsolutiondetails=&solutionid=sk92881&js_peid=P-114a7ba5fd7-10001&partition=General&product=Endpoint

    This had nothing to do with the app or the capabilities (not directly at least) but was caused by an incompatibility with the VPN.

    Prashant H Phadke thank you for your time. I mark your answer cause it should solve this issue in most cases.

    • Marked as answer by Enro67 Wednesday, May 28, 2014 12:48 PM
    • Edited by Enro67 Wednesday, May 28, 2014 2:01 PM
    Wednesday, May 28, 2014 12:48 PM