JG Vimalan's Blog

It is all about coding!

Cannot have two operations in the same contract with the same name, methods…

I was trying to do method overloading in my WCF 4.0 service and the code complied well but, while trying to open the service in test client, it throwed an error,

Cannot have two operations in the same contract with the same name, methods…

The code is as follows,

To fix this issue, I added “Name” attribute in the OperationContract as shown below,

This fixed the issue. And, while viewing the service in test client, observed that, the method name is exposed as  “GetFullNameByID” as shown below,


April 19, 2012 Posted by | WCF | Leave a comment

The communication object, System.ServiceModel.ChannelFactory…, cannot be used for communication because it is in the Faulted state.

I got the error message (The communication object, System.ServiceModel.ChannelFactory…, cannot be used for communication because it is in the Faulted state.) in the production system, which was working fine for months. I found that, the WCF service is up and running and it is able to connect to database and is connected to the application as well. So, to fix this issue I followed the steps given below.

a. Stop the application pool of the application which is consuming the WCF service.

b. Browse to the C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files

c. Delete the temp folder of the application which is using the WCF service. (The reason is, even though you restart IIS, the corrupted files will be here and it will cause the issue)

e. Start the application pool.

That’s it! This resolved my issue and the application started to work normally. Although, I am not clear on what exactly happened to cause this issue, I found the solution.

September 8, 2011 Posted by | ASP.NET, WCF | 1 Comment

Consuming WCF service in Android application

In order to consume WCF service in an Android application, the WCF Service must send and receive data in JSON format. So, you need to set the RequestFormat and ResponseFormat to JSON, in the WebInvoke attribute as shown below,

using System.ServiceModel;
using System.ServiceModel.Web;

    public interface IService
        [WebInvoke(Method = “POST”,
        UriTemplate = “/GetEmployee”,
        RequestFormat = WebMessageFormat.Json, 
        ResponseFormat = WebMessageFormat.Json)]
        Employee GetEmployee(EmployeeIdentity request);

I used wsHttpBinding in my WCF service.  

Now, to consume the WCF Service in your Android application, use httpClient to process the request and get the response. A sample code is given below,

HttpClient httpClient = null;
HttpUriRequest httpUriRequest = null
HttpResponse httpResponse = null;

try {
httpUriRequest = //build request
httpClient = new DefaultHttpClient();
httpResponse = httpClient.execute(httpUriRequest);

October 29, 2010 Posted by | Android, JSON, WCF | 1 Comment

Consuming WCF service in Silverlight application

In order to consume WCF service in your silverlight application, add the WCF Service as a service reference in your Silverlight application. Once you do that, you can see a ServiceReferences.ClientConfig file in your silverlight project. It will have the binding information and the endpoint as shown below,

                <binding name=”basicEndPoint” maxBufferSize=”2147483647″ maxReceivedMessageSize=”2147483647″>
                    <security mode=”None” />
            <endpoint address=”http://mySystem/WCFService/Manager.svc” binding=”basicHttpBinding”
                bindingConfiguration=”basicEndPoint” contract=”SampleWCFService.IManager”
                name=”basicEndPoint” />

So, its time to invoke the methods exposed by the WCF service. In silverlight, it is slightly different when compared to asp.net web application. You will call the asynchronous method and handle its completed event, where you get the result.

private void button1_Click(object sender, RoutedEventArgs e)
            SampleWCFService.ManagerClient client = new

            client.GetEmployeesCompleted += new

            client.GetEmployeesAsync(); //invoke the GetEmployees method here

        void client_GetEmployeesCompleted(object sender, SampleWCFService.GetEmployeesCompletedEventArgs e)
            //you will get the result object here
            System.Collections.ObjectModel.ObservableCollection<SampleWCFService.Employee> employees =

            if (employees.Count() > 0)
                //put code here

October 21, 2010 Posted by | Silverlight, WCF | 1 Comment

The server did not provide a meaningful reply; this might be caused by a contract mismatch

This issue occured when my client system tried to receive a large amount of data from a WCF service. So, to fix this exception, I added the ServiceBehaviour in both client application and WCF service. In the ServiceBehaviour, add DataContractSerializer and set its maxItemsInObjectGraph to higher value.

        <behavior name=”WCFService.Service1Behavior”>
          <serviceMetadata httpGetEnabled=”true” />
          <serviceDebug includeExceptionDetailInFaults=”true” />
          <dataContractSerializer maxItemsInObjectGraph=”2147483647″ />

Also, set the behaviour name in the behaviour configuration under service tag.

      <service behaviorConfiguration=”WCFService.Service1Behavior”
        <endpoint address=”” behaviorConfiguration=”” binding=”basicHttpBinding”
          bindingConfiguration=”TestBinding” name=”basicEndPoint” contract=”WCFService.IManager”>
            <dns value=”localhost” />

October 20, 2010 Posted by | WCF | Leave a comment

System.ServiceModel.Dispatcher.NetDispatcherFaultException: The formatter threw an exception while trying to deserialize the message

This exception is thrown when your client application receives a large data from WCF service and it is not able to deserialize them. So, you have to set the DataContractSerializer property in the EndPointBehaviour in your client application. To do that, you can edit your web.config file using WCF Service Configuration Editor (available in the VS -> tools menu)

Add the endpointbehaviour and set its name under the client endpoint tag. Once you do that, your web.config will look like,

                <behavior name=”NewBehavior”>
                    <dataContractSerializer maxItemsInObjectGraph=”2147483647″ />


            <endpoint address=”http://mySystem/WCFService/Manager.svc” behaviorConfiguration=”NewBehavior”
                binding=”basicHttpBinding” bindingConfiguration=”basicEndPoint”
                contract=”MyServiceReference.IManager” name=”basicEndPoint” />

October 20, 2010 Posted by | WCF | Leave a comment