Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Problems calling exteral web service

Posted on by Microsoft Employee

Hi all,

I'm currently developing on CRM 2013 on-premise and have been trying to develop a plug in that will ultimately send CRM data to an external system via their web service.

I have created a plugin and added a method that logs into the service which is called from ExecutePostContactUpdate.  When I registered the plugin in the Sandbox the plugin errored out with the following:

<ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic" />
  <Message>System.Security.SecurityException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #904A5CD2</Message>

When I then select an Isolation mode of None I get the following which, while a slight improvement is still not working:

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: There was no endpoint listening at xxx.com/.../basic that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.Detail:
<OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts">
  <ErrorCode>-2147220891</ErrorCode>
  <ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic">
    <KeyValuePairOfstringanyType>
      <d2p1:key>OperationStatus</d2p1:key>
      <d2p1:value xmlns:d4p1="www.w3.org/.../XMLSchema" i:type="d4p1:string">0</d2p1:value>
    </KeyValuePairOfstringanyType>
    <KeyValuePairOfstringanyType>
      <d2p1:key>SubErrorCode</d2p1:key>
      <d2p1:value xmlns:d4p1="www.w3.org/.../XMLSchema" i:type="d4p1:string">-2146233088</d2p1:value>
    </KeyValuePairOfstringanyType>
  </ErrorDetails>
  <Message>There was no endpoint listening at https://xxx.com/ExteranlService/basic that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.</Message>
  <Timestamp>2017-08-18T09:44:53.8400131Z</Timestamp>
  <InnerFault i:nil="true" />
  <TraceText>

[IVPContact: IVPContact.PostContactUpdate]
[f882f15c-5183-e711-86c0-005056a95391: IVPContact.PostContactUpdate: Update of contact]
Entered IVPContact.PostContactUpdate.Execute(), Correlation Id: 810a2ba9-8821-4417-91ce-ae32d1c54ad2, Initiating User: aef9440c-b1e1-e311-8a43-005056a95391
IVPContact.PostContactUpdate is firing for Entity: contact, Message: Update, Correlation Id: 810a2ba9-8821-4417-91ce-ae32d1c54ad2, Initiating User: aef9440c-b1e1-e311-8a43-005056a95391
Exiting IVPContact.PostContactUpdate.Execute(), Correlation Id: 810a2ba9-8821-4417-91ce-ae32d1c54ad2, Initiating User: aef9440c-b1e1-e311-8a43-005056a95391

</TraceText>
</OrganizationServiceFault>

I know that the code works as I have tested it in a separate console app and I can connect without issue.

The code in the plugin is as follows:

        protected void ExecutePostContactUpdate(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

            // TODO: Implement your custom Plug-in business logic.
            IPluginExecutionContext context = localContext.PluginExecutionContext;
            IOrganizationService service = localContext.OrganizationService;


            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
            {
                Entity entity = (Entity)context.InputParameters["Target"];

                if (entity.LogicalName == "contact")
                {
                    string loginTest = ivpLogin();
                    throw new InvalidPluginExecutionException(loginTest);
                }
            }
        }

        private string ivpLogin()
        {
            BasicHttpBinding binding = new BasicHttpBinding();
            binding.Name = "BasicHttpBinding_ExternalWebService";

            binding.CloseTimeout = System.TimeSpan.Parse("00:01:00");
            binding.OpenTimeout = System.TimeSpan.Parse("00:01:00");
            binding.ReceiveTimeout = System.TimeSpan.Parse("00:01:00");
            binding.SendTimeout = System.TimeSpan.Parse("00:01:00");

            binding.AllowCookies = false;
            binding.BypassProxyOnLocal = false;
            binding.HostNameComparisonMode = System.ServiceModel.HostNameComparisonMode.StrongWildcard;

            binding.MaxBufferSize = 65536;
            binding.MaxBufferPoolSize = 524288;
            binding.MaxReceivedMessageSize = 65536;

            binding.MessageEncoding = System.ServiceModel.WSMessageEncoding.Text;
            binding.TextEncoding = System.Text.Encoding.UTF8;
            binding.TransferMode = System.ServiceModel.TransferMode.Buffered;

            binding.UseDefaultWebProxy = true;
            binding.ReaderQuotas.MaxDepth = 32;
            binding.ReaderQuotas.MaxStringContentLength = 8192;

            binding.ReaderQuotas.MaxArrayLength = 16384;
            binding.ReaderQuotas.MaxBytesPerRead = 4096;
            binding.ReaderQuotas.MaxNameTableCharCount = 16384;

            binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;

            binding.Security.Transport.Realm = "";
            binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
            binding.Security.Message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default;

            EndpointAddress endpoint = new EndpointAddress("xxx.com/.../basic");

            client = new ExternalWebServiceClient(binding, endpoint);

            requestInfo = new RMLoginRequestInfo();
            requestInfo.DeviceKey = Guid.NewGuid().ToString();
            requestInfo.UserName = _userName;
            requestInfo.Password = _passWord;
            loginResponse = client.Login(requestInfo);

            if (loginResponse.IsSuccess)
            {
                return "true";
            }
            else
            {
                return "false";
            }


Many Thanks for any help given!

*This post is locked for comments

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Problems calling exteral web service

    Hi,

     Aren't you supposed to specify HTTP/https in the endpoint address URL? It seems to be complaining that there is nothing at that address..

    docs.microsoft.com/.../specifying-an-endpoint-address

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Problems calling exteral web service

    Assuming code is fine (as it works in console) and looking at exception that service is not reachable.

    Can you verify from your CRM Servers that service is reachable . In many environments for security reason (hardening) we stop outgoing calls.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans