Calling WCF Service in Plugin in CRM

Suppose this is our simple WCF Service.

   public interface IService1
       string GetData(); 

public class Service1 : IService1
       public string GetData()
           return “Hello World”+DateTime.Now.ToLongTimeString();

Now if we add its service reference in our plugin and then deploy it, while running we would receive this error.

Could not find default endpoint element that references contract ‘ServiceReference1.IService1’ in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

The reason for this is because the configuration information for the WCF service from the client side is missing. As class library won’t have their own config file.

Suppose if we add service reference to the above Service in a windows application, we can find the following information being added to the app.config file

<?xml version=”1.0″ encoding=”utf-8″ ?>
                <binding name=”BasicHttpBinding_IService1″ 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”
                    <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” />
            <endpoint address=”http://localhost:58844/Service1.svc” binding=”basicHttpBinding”
                bindingConfiguration=”BasicHttpBinding_IService1″ contract=”ServiceReference1.IService1″
                name=”BasicHttpBinding_IService1″ />

So now in case of our plugin we need to define the binding and endpoint information programmatically, something like this



BasicHttpBinding myBinding = new

myBinding.Name = “BasicHttpBinding_IService1”;

myBinding.Security.Mode = BasicHttpSecurityMode.None;

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

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

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

EndpointAddress endPointAddress = new

ServiceReference1.Service1Client myClient = new ServiceReference1.Service1Client(myBinding, endPointAddress);



catch (Exception EX)



throw EX;



This way we would be able to access our WCF service inside plugin.

Hope it helps !

Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

20 thoughts on “Calling WCF Service in Plugin in CRM”

  1. Hello, I´m trying to apply this code over the online version of CRM 2011. The only way to publish a plugin in an online version is in a “sandbox” mode. Could you tell me is this solution will work fine?


  2. Hello,

    I have created WCF service which internally update the my SQL table and I using one of the WCF method in my CRM 2011 online plug-in but plug-in throws exception. I have used same way to call the WCF method as mentioned in the post.

    Is WCF service is allowed in CRM 2011 online plug-in or not?

    Thanks in Advance.


    1. Hi , I am able to call the WCF if the plugin registered in Post , Async operation . But I need to call the WCF in Synchronous mode . When i tried this am getting “Generic SQL Error”.
      Please help me to sort out this


  3. Hi ,
    Your post saved my time a lot.

    I am calling a AX WCF web service in my Plugin and so i am using your way.

    But it gives me error.
    When i debugged i got “null” in UserName.

    What can i do in this ?
    Is anything i am missing here.


  4. Hi Nishant,

    I have created a service with a method that returns the string “Testing”. The WCF service is hosted in Windows Azure and I have created a Console Application which can call the method successfully. However, when consumed from within a plug-in, I receive the following error:

    System.Runtime.Serialization.InvalidDataContractException: Type ‘System.Threading.Tasks.Task’1 [System.String] cannot be serialized. Consider marking it with the DataContractAttribute attribute and marking all of its members you want serialized with the DataMemberAttribute attribute…

    I am testing from an on-premise implementation of CRM, but this will also need to work for CRM 2011 online. Any ideas of how I can fix this?


  5. You’ve made some decent points there. I checked on the net for more information about the issue and found most people will go along with your views on this site.


  6. Unfortunately, different people produce this hormone at different rates, which is why
    some people have trouble generating lean muscle growth. ‘We want to carefully research the potential benefits of velvet antler supplements for supporting the immune system, anti-aging, muscle strength and endurance, and sexual vitality. Fillers, binders, lubricants, and the like do not have to be listed and often aren’t.


  7. Hi Nishanth ,

    I am using the same format only but still I am getting the same error. May I know why.

    What is in the url “&#8221” argument ? http://localhost:58844/Service1.svc&#8221;

    Actually I need to call a Rest API from my plugin (Using RestSharp) but I am getting error so I thought at least I can create SOAP service from plugin and call the rest api from that.

    Liked by 1 person

Please share your thoughts

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.