WCF: Contract name is inconsistent on the client side

WCF: Contract name is inconsistent on a client side.

Sometimes we’ve got a very clear fault message:    

 

    <faultstring xml:lang="en-US">Could not find default endpoint element that references contract 'ServiceProvider_configuration_Ref.ConfigurationServicePortType' 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.</faultstring>
         <detail>
            <ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
               <HelpLink i:nil="true"/>
               <InnerException i:nil="true"/>
               <Message>Could not find default endpoint element that references contract 'ServiceProvider_configuration_Ref.ConfigurationServicePortType' 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.</Message>
….

It means two things do not conform each other:

1)      contract attribute in the endpoint element of a config file:

   <endpoint address="https://ie-services-configuration.ServiceProvider.com"

binding="customBinding" bindingConfiguration="customBinding_Configuration"    contract="MyCompany.MyProject.ServiceProvider_configuration_Ref.ConfigurationServicePortType"

      name="ConfigurationServiceHttpPort" />

 

2)       And ConfigurationName property of a ServiceContract attribute in a proxy code. It usually generated by Add Service Reference wizard and placed in a hidden file the Reference.cs

     [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]

    [System.ServiceModel.ServiceContractAttribute(
Namespace="http://ws.ServiceProvider.com", ConfigurationName="ServiceProvider_configuration_Ref.ConfigurationServicePortType")]

    public interface ConfigurationServicePortType {

 

How I could get this situation? Very easily. For instance when I am editing my .config file with the Microsoft Service Configuration Editor and selecting to fix my endpoint -> contract name. I choose the dll with the definition of the service contract and there we go! It shows me not the ServiceProvider_configuration_Ref.ConfigurationServicePortType but MyCompany. MyProject.ServiceProvider_configuration_Ref.ConfigurationServicePortType and this creates the error mentioned above.

 

We fix this error easily by changing the config file. Of course we can change the Reference.sc but it is generated be wizard and after updating this reference the error appears again.

 

Is it a whole story? Nope. It is more interesting.

 

Say we have the source code for this Web-service. Then we are creating the client for this Web-service. We are waiting that the full name of the service class should be the same in the service source code and in the client proxy code. It’s wrong! It is completely wrong.

That means the “loose coupling” J All the client could get from the service in terms of data definition is the metadata: one or many wsdl-s and schemas (xsd).  Inside this is the contract name. Usually it is the name of service interface or, if you apply the [ServiceContract] right to the service class, the service class name. The namespaces of the service, data, etc. contracts do not passed by the metadata! When one of the client tools generates the proxy code it usually adds some new namespace. For example the Visual Studio adds the Default namespace parameter from the project properties.

What about the service class name? The metadata passes the name under the [ServiceContract] attribute. And the client tool that generates the proxy code does not know is it the name of the interface or the name of the class. Then is just creates the interface with this name and with the [ServiceContract] attribute. Then it creates the class derived from this interface. And this class has auto generated name!

What about the service contract full name?

For instance:

the source code of the web-service:

namespace CMS_Stub {…

 [ServiceContract(
Namespace = " http://ws.ServiceProvider.com ")]

public interface ICMS_Stub

public class CMS_StubService : ICMS_Stub

 

the client proxy code:

namespace MyCompany. MyProject.ServiceProvider_configuration_Ref {…

[ServiceContract(
Namespace = " http://ws.ServiceProvider.com ",
ConfigurationName="ServiceProvider_configuration_Ref.ICMS_Stub")]

public interface ICMS_Stub

public class CMS_StubClient: ICMS_Stub

 

And what we see in the contract attribute in the endpoint element of the client config file?

  • CMS_Stub.ICMS_Stub?
  • CMS_Stub.CMS_StubService?
  • MyCompany.MySolution.MyProject.DownloadUri.ServiceProvider_configuration_Ref.ICMS_Stub?
  • MyCompany.MySolution.MyProject.DownloadUri.ServiceProvider_configuration_Ref.CMS_StubClient?
  • ServiceProvider_configuration_Ref.ICMS_Stub?

Yes, you are right, the last one, the ConfigurationName of the ServiceContract.

 

 

 

Print | posted on Friday, April 25, 2008 8:40 AM

Feedback

# re: WCF: Contract name is inconsistent on the client side

left by Suji Babu at 11/8/2008 12:27 PM Gravatar
Awesome fix. Thanks!

# re: WCF: Contract name is inconsistent on the client side

left by wcfUser at 7/14/2009 8:34 AM Gravatar
Okay, and is there a solution to avoid this kind of issue? I cannot overcome, the error keeps popping up. What can I do to eliminate the faulty naming of the framework?

# re: WCF: Contract name is inconsistent on the client side

left by Leonid Ganeline at 7/14/2009 10:08 AM Gravatar
I know only one method. :( After regenerating proxy code I manually fix it.
In VS2008 we have more options when we are generating this code with Add Service Ref..., but not too much. These options are not helpfull on this kind of issues.

# re: WCF: Contract name is inconsistent on the client side

left by Alden Snow at 10/20/2009 3:56 PM Gravatar
Does anyone know if this can things be simplified by leaving out configuration names and namespaces? And can everything on the service side be specified in code?

Or, can something be fixed in the service so that the proxy class will get generated in a way that we won't get this message?

I get this error without going into Microsoft Service Configuration Editor and selecting to fix my endpoint.

# re: WCF: Contract name is inconsistent on the client side

left by zulaff at 10/27/2009 11:15 AM Gravatar
I had the same error text, but a different problem and solution: I'm not quite sure what the problem was, but the solution was to move all the information regarding the connection, from my app.config (local config file for that project) to my global web.config. I don't know why it can't be in the app.config file though?

# re: WCF: Contract name is inconsistent on the client side

left by BorodaAlex at 3/19/2010 2:25 AM Gravatar
A also moved the section with client contract-endpoint description from app.config to my common config file and this resolved the problem
Post A Comment
Title:
Name:
Email:
Comment:
Verification: