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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to consume a web service in CRM using plugin.

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Emre GULCAN Profile Picture
    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 ?

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

    call external webservice

  • Verified answer
    Ivan Ficko Profile Picture
    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.

  • Alessandro Graps Profile Picture
    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.

  • Suggested answer
    Community Member Profile Picture
    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) { }

                       }

                   }

               }

           }

  • ashlega Profile Picture
    34,477 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

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
UllrSki Profile Picture

UllrSki 2

#1
Community Member Profile Picture

Community Member 2

#3
SC-08081331-0 Profile Picture

SC-08081331-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans