Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

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

(0) ShareShare
ReportReport
Posted on by 547

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

 

CRM Version 1612 (8.2.2.112) (DB 8.2.2.112)
* .Net Framework 4.5.2

*This post is locked for comments

  • chikhaleankush Profile Picture
    chikhaleankush 547 on at
    RE: CRM OnPrem--> Plugin--> Connect to External (SOAP) Webservice Error with connection

    Here is the Code Snippet

    byte[] bytes;

                   bytes = System.Text.Encoding.ASCII.GetBytes(xml);

                   WebProxy proxy = new WebProxy("proxy.xyz.local" /*this should be proxy of your server */, 81 /*Port Number */) { UseDefaultCredentials = true };

                   WebRequest request =

                       WebRequest.Create("www.abc.com" /*external webapi url*/);

                   request.Proxy = proxy;

                   request.Method = "POST";

                   request.Credentials = new NetworkCredential(username,password); /*If needed*/

                   request.ContentType = "application/xml; encoding='utf-8'";

                   request.ContentLength = bytes.Length;

                   Stream requestStream = request.GetRequestStream();

                   requestStream.Write(bytes, 0, bytes.Length);

                   requestStream.Close();

                   var response = (HttpWebResponse)request.GetResponse();

                   if (response.StatusCode == HttpStatusCode.Created)

                   {

                       isPostMethodSucessfull = true;

                       tracing.Trace($" Resposne is correct i.e Record is created {response.StatusDescription}");

                   }

                   else

                   {

                       tracing.Trace($"Response is not correct from connecting to API {response.StatusCode}");

                   }

  • chikhaleankush Profile Picture
    chikhaleankush 547 on at
    RE: CRM OnPrem--> Plugin--> Connect to External (SOAP) Webservice Error with connection

    Yeah you were right :)

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: CRM OnPrem--> Plugin--> Connect to External (SOAP) Webservice Error with connection

    Great, share the code you have added here and close the thread by marking it as answer. It may help somene else facing the same/ similar issue.

  • Dynamics365 Rocker Profile Picture
    Dynamics365 Rocker 7,755 on at
    RE: CRM OnPrem--> Plugin--> Connect to External (SOAP) Webservice Error with connection

    Great, I told you that there may be firewall issue.

  • Verified answer
    chikhaleankush Profile Picture
    chikhaleankush 547 on at
    RE: CRM OnPrem--> Plugin--> Connect to External (SOAP) Webservice Error with connection

    Reason why it was not working:

    Customer (OnPrem) uses Proxy to connect to Web.

    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.

    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.

    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.

  • chikhaleankush Profile Picture
    chikhaleankush 547 on at
    RE: CRM OnPrem--> Plugin--> Connect to External (SOAP) Webservice Error with connection

    You Mean by Server on which On Prem CRM is hosted. Yes I did tried it from there and it worked.

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: CRM OnPrem--> Plugin--> Connect to External (SOAP) Webservice Error with connection

    Hi,

    Did you verify if you are able to connect to the api from your CRM server?

  • chikhaleankush Profile Picture
    chikhaleankush 547 on at
    RE: CRM OnPrem--> Plugin--> Connect to External (SOAP) Webservice Error with connection

    I already did that.

    "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."

  • Suggested answer
    Temmy Wahyu Raharjo Profile Picture
    Temmy Wahyu Raharjo 2,914 on at
    RE: CRM OnPrem--> Plugin--> Connect to External (SOAP) Webservice Error with connection

    Usually I will create console application and deploy it into the CRM front end server to testing my code can run first. If on that front end you can debug, just debug it.

  • chikhaleankush Profile Picture
    chikhaleankush 547 on at
    RE: CRM OnPrem--> Plugin--> Connect to External (SOAP) Webservice Error with connection

    No I have no external DLL's Merged and hence No need for ILmerge. Simple HTTPClient connect I am trying to use.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,407 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans