Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

How to consume a web service in CRM using plugin.

Posted on by Microsoft Employee

Hi,

I try to call a web service in plugin,th web service  create a contact, so i need to call this service in plugin where the message is crate and the primary entity is account,

please some one publish an example some..

thank you 

*This post is locked for comments

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: How to consume a web service in CRM using plugin.

    Is it working now?

    If not, you might actually want to try it in a console app first. There are some limitations when you deploy plugins in sandbox:

    msdn.microsoft.com/.../gg334752.aspx

    For example, "localhost" is not allowed..(have to use a dns name instead)

    Although, if you are onprem, you don't have to use sandbox

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to consume a web service in CRM using plugin.

    this is my code

    public class Class1 : IPlugin

       {

           public void Execute(IServiceProvider serviceProvider)

           {

               //Context = Info passed to the plugin at runtime

               IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

               IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

               //Service = access to data for modification

               IOrganizationService service = factory.CreateOrganizationService(context.UserId);

               // Adding Basic Http Binding and its properties.

               BasicHttpBinding myBinding = new BasicHttpBinding();

               myBinding.Name = "BasicHttpBinding_Service";

               myBinding.Security.Mode = BasicHttpSecurityMode.None;

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

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

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

               if (context.InputParameters.Contains("Target") && (context.InputParameters["Target"] is Entity))

               {

                   {

                       Entity entity = (Entity)context.InputParameters["Target"];

                       if (entity.LogicalName == "account")

                       {

                           try

                           {

                               // Endpoint Address defining the asmx Service to be called.

                               EndpointAddress endPointAddress = new EndpointAddress(@"localhost/WebService1.asmx;);

                               // Call to the Web Service using the Binding and End Point Address.

                               localhost.WebService1 srv = new localhost.WebService1();

                               srv.CreateContact();

                           }

                           catch (Exception ex) { }

                       }

                   }

               }

           }

  • Alessandro Graps Profile Picture
    Alessandro Graps 2,664 on at
    RE: How to consume a web service in CRM using plugin.

    Hi, you can see this example: code.msdn.microsoft.com/.../How-to-call-Rest-Service-b0b188df

    thanks

    A.G.

  • Verified answer
    Ivan Ficko Profile Picture
    Ivan Ficko 1,380 on at
    RE: How to consume a web service in CRM using plugin.

    The only thing you need to know about this one is that you need to configure your SOAP webservice inside your plugin code. Configuration that is generated by adding web service reference will not work in CRM plugin.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to consume a web service in CRM using plugin.

    call external webservice

  • Emre GULCAN Profile Picture
    Emre GULCAN 2,379 on at
    RE: How to consume a web service in CRM using plugin.

    Hi Ghazi,

    Do you want call external webservice or want to use IOrganizationService ?

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans