Search code examples
dynamics-crmcrmmicrosoft-dynamics

CRM OnPrem--> Plugin--> Connect to External (SOAP) Webservice Error with connection


I am trying to connect from CRM Plugin to External SOAP API. It gives me error.

I am using Isolation Mode as None. When I connect the same API using Console APP it works fine. I executed the Console APP from Server and it connects and responds Fine.

I googled a bit got some leads but probably I lack capability to understand/ pinpoint the issue.

Code Snippet below

WebRequest request = WebRequest.Create("URL");                  

                    request.Method = "GET";

                    //request.Credentials = new NetworkCredential("USERNAME", "PASSWORD");

                    WebResponse response = request.GetResponse();

                    HttpWebResponse webresponse = (HttpWebResponse)response;
                    if (webresponse.StatusCode == HttpStatusCode.OK)
                    {
                        tracing.Trace($" Resposne is correct i.e OK");

                    }

When I debug using Plugin Registration Tool, Tool breaks up and exits.


Error from Tracing:

 A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond


    at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)

       at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
       --- End of inner exception stack trace ---
       at System.Net.HttpWebRequest.GetResponse()

Solution

  • Reason why it was not working:

    1. Customer (OnPrem) uses Proxy to connect to Web.
    2. When I was running Console App on server it was running on my Logged on context (outside CRM) i.e. user who logged on Server.
    3. However, When I tried to call website from CRM may it be from Isolation Mode = None OR Sandbox, The services that runs under specific user did not have proxy added to them.
    4. For Example running plugin under Isolation Mode = NONE i.e. directly under the context of APPPool Service "crmtestappserv" did not have proxy and even using mere Internet Explored under the context of same user was not able to open google.com unless proxies were Added.

    Steps Taken to Solve the issue: In our plugin Code, when we make an HTTP request we add proxy to the request. This solved our issue.