Search code examples
web-servicespluginssoapdynamics-crm

Calling a soap web service from Microsoft CRM plugin


I have a plugin which calls a soap based web service on creation of a new contact.Its a simple soap web service which displays a welcome message when called

Below is app.config which contains all configuration requirements.

<?xml version="1.0"?>
        <configuration>
            <system.serviceModel>
                <bindings>
                    <basicHttpBinding>
                        <binding name="WelcomeBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
                        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
                        <security mode="None">
                            <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
                            <message clientCredentialType="UserName" algorithmSuite="Default"/>
                        </security>
                    </binding>
                </basicHttpBinding>
            </bindings>
            <client>
                <endpoint address="http://revesinc.com/WelcomeSeamService/Welcome" binding="basicHttpBinding" bindingConfiguration="WelcomeBinding" contract="ServiceReference1.Welcome" name="WelcomePort"/>
            </client>
        </system.serviceModel>
    <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

and below is C# plugin code

BasicHttpBinding myBinding = new BasicHttpBinding();    
myBinding.Name = "WelcomeBinding";
myBinding.Security.Mode = BasicHttpSecurityMode.None;
myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;                       
myBinding.Security.Message.ClientCredentialType =                   BasicHttpMessageCredentialType.UserName;
                    EndpointAddress endPointAddress = new EndpointAddress("http://revesinc.com/WelcomeSeamService/Welcome");
WelcomeClient client = new WelcomeClient(myBinding,endPointAddress);

when i create a contact in CRM, nothing gets displayed on my server. there is no exception on CRM side either. Any idea??? thanks


Solution

  • At first I want to ask you how are you going to display something on your server? I don't see any way to do this using plugin, but might be I'm not right. In any case, please, show part of code where you are displaying something.
    You are saying that nothing happen. At first you should check that the plugin is registered properly. As I understood, you should check that there was added step with entity Contact and Message Create. Also usually plugins are created using some templates. Might be some error is in the part of your code, before calling Web Service.
    And another issue I want to emphasize. You have a config file with the configurations of your assembly. I think that for plugin assemblies is better to do not store any configurations in config files, but do all the settings in code.
    There are few different ways to check that plugin was fired. At first you can deploy not only dll but also pdb files and attach to the IIS process with the debugger. If there is no Visual Studio installed, you can use Remote Debugger. If it's not possible due some reason, you can throw PluginExecutionException at the beginning of your code to be sure that plug in is really called. And when you will be sure that plug in is working, you can start test working with Web Service.