web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

External Web Service call fails from within Plugin

(0) ShareShare
ReportReport
Posted on by 95

Hello -

I've been bashing my head against a wall trying to figure out why I can not call to an external web service from a plugin. I've been able to make a dummy project and connect to the web service and get a result. Once I move the code into a plugin I get a timeout error. Even when I try to do a basic Get using the WebRequest object it returns a timeout.

Server was unable to process request. ---> Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

The statement has been terminated.

The service is not on the local machine. I can hit the service in a basic web project, through browser, and using SOAPUI. Below is the variations of code I've gone through...any ideas?

//attempt 1

LicenseWS.LicenseWebService ws = new LicenseWS.LicenseWebService();

string result = ws.GetFullLicenseKey("XXX", "11111111111");

//attempt 2

LicenseWS.LicenseWebServiceSoapClient ws = new LicenseWS.LicenseWebServiceSoapClient("LicenseWebServiceSoapClient");

string result = ws.GetFullLicenseKey("XXX", "11111111111");

ret.LicenseBody = result;

//attempt 3

string url = "http://WEBDEV03/crmlicensews/license.asmx";

BasicHttpBinding binding = new BasicHttpBinding();

EndpointAddress address = new EndpointAddress(url);

LicenseWS.LicenseWebServiceSoapClient LicenseSrv = new LicenseWS.LicenseWebServiceSoapClient(binding, address);

string result = LicenseSrv.GetFullLicenseKey("XXX", "11111111111");

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Hosk Profile Picture
    on at

    What CRM are you using.

    if it's CRM online there maybe a problem because the plugins run in the sandbox and going out to a webservice may break the transaction and thus erroring.

    Also is the user you are using to connect to the webservice, does he have permission.

    Can you connect to the webservice from the crm server (if it's onpremise)

    Can you give us a little bit more information about what version of CRM you are using.

    Cheers

    Ben

  • Danc Profile Picture
    95 on at

    Thanks. I'm on CRM 2011 local install. I have two functions on the web service. The first just returns a true value and when I call that function everything seems to work. The second function contains a bunch of db calls, which seems to timeout when the first db call is reached.

    I set the plugin to fire using an admin account (me).

    I've made a little progress was just able to actually watch the plugin fire the web service. When it reaches the first fucntion that does a db call it returns the following message:

    System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

    If I run the web service outside of the plugin no errors are thrown and we get the expected result.

    Here is the StackTrace returned from the plugin:

    Server stack trace:

      at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)

      at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)

      at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)

      at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

    Exception rethrown at [0]:

      at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

      at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

      at crmGenerateLicense.LicenseWS.LicenseWebServiceSoap.GetFullLicenseKey(GetFullLicenseKeyRequest request)

      at crmGenerateLicense.LicenseWS.LicenseWebServiceSoapClient.crmGenerateLicense.LicenseWS.LicenseWebServiceSoap.GetFullLicenseKey(GetFullLicenseKeyRequest request)

      at crmGenerateLicense.LicenseWS.LicenseWebServiceSoapClient.GetFullLicenseKey(String System, String LicenseNumber)

      at crmGenerateLicense.AppCode.GenerateLicenseFile(Guid LicenseId, String LicenseNo, String LicenseServiceUrl, String LicSystem, OrganizationServiceContext orgContext, IOrganizationService service)

    Here's the latest call I'm using from in the Plugin:

       binding.Name = "BasicHttpBinding_Service";

                   binding.Security.Mode = BasicHttpSecurityMode.None;

                   binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;

                   binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;

                   binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

                   binding.SendTimeout = TimeSpan.MaxValue;

                   binding.ReceiveTimeout = TimeSpan.MaxValue;

                   binding.CloseTimeout = TimeSpan.MaxValue;

                   binding.OpenTimeout = TimeSpan.MaxValue;

                   binding.TransferMode = TransferMode.Streamed;

                   EndpointAddress address = new EndpointAddress(url);

                   LicenseWS.LicenseWebServiceSoapClient LicenseSrv = new LicenseWS.LicenseWebServiceSoapClient(binding, address);

  • Danc Profile Picture
    95 on at

    One other note, here is the call made from the web service. When I run the proc directly on the db I get results in less than a second.

    Public Shared Function GetLockedLicenses(ByVal licensenumber As String, ByVal system As String) As DataTable

           Dim table As DataTable = New DataTable

           Dim db As String = system.ToUpper()

           Using con As New SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings(db).ToString)

               Dim command As New SqlClient.SqlCommand("LicenseWS_GetLicenses", con)

               command.CommandType = CommandType.StoredProcedure

               command.Parameters.Add(New SqlClient.SqlParameter("@LicenseNo", SqlDbType.NVarChar, 100))

               command.Parameters("@LicenseNo").Value = licensenumber

               con.Open()

               Dim adapter As SqlDataAdapter = New SqlDataAdapter(command)

               adapter.Fill(table)

           End Using

           Return table

       End Function

  • Suggested answer
    Lozici Cezar Profile Picture
    890 on at

    Hi Danc,

        I would say that you could try to dig deeper to see why you are getting a SQL Timeout. You mentioned you are making DB calls ,if you are reaching indeed the database you should be able to see this information by looking at the CRM Server traces (in verbose) or in SQL Profiler trace to maybe gain some more information. I am not aware of the type of this 1st call you mention is timing out but you could try and eliminate it to see if it's the only call with issues or you would get this regardless of the DB query you are making.

       I would recommend you as well to contact the Technical Support Team though a Support Ticket to have a closer look at your issue.

    Thank you for using Microsoft Dynamics CRM Communities

    Cezar Lozici

    Support Engineer

    Microsoft Dynamics CRM

  • Suggested answer
    Vijay Waghmare Profile Picture
    on at

    MS CRM plug-in (synchronous or asynchronous) has time limit of 2-minutes.  If the plugin execution (web service call) exceeds the time limit, a System.TimeoutException is thrown.

    If a operation required processing time more than 2-minute, consider using a custom workflow to accomplish your functionality.

    Thanks,

    Vijay Waghmare

  • Danc Profile Picture
    95 on at

    Thanks for the responses. I've debugged the web service and the response is within a few seconds. Not sure what is going on there.

    I was running up against a timeline so I ended up moving the web service call from a plugin to a web page that I call from the within CRM.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans