54

The contract name 'IMyService' could not be found in the list of contracts implemented by the service 'MyService'.. ---> System.InvalidOperationException: The contract name 'IMyService' could not be found in the list of contracts implemented by the service 'MyService'.

This is driving me crazy. I have a WCF web service that works on my dev machine, but when I copy it to a Virtual Machine that I am using for testing, I get the error that seems to indicate that I am not implementing the interface, but it does not make sense because the service does work on my windows xp IIS. the Virtual machine uses Windows Server 2003 IIS. Any ideas?

One thing to note here is that I get this error on my VM even while just trying to access the service in a web browser as the client.

Note: I am using principalPermissionMode="UseWindowsGroups", but that is not a problem on my local machine. I just add myself to the appropriate windows group. But no luck on my VM.

Config:

<configuration>
    <system.serviceModel>
        <diagnostics>
            <messageLogging logEntireMessage="false" maxSizeOfMessageToLog="2147483647" />
        </diagnostics>
        <services>
            <service behaviorConfiguration="MyServiceBehaviors" name="MyService">
                <endpoint binding="basicHttpBinding" bindingConfiguration="basicHttpBinding"
                  name="MyService" bindingName="basicHttpBinding" bindingNamespace="http://my.test.com"
                  contract="IMyService">
                </endpoint>
            </service>
        </services>
        <bindings>
            <basicHttpBinding>
                <binding name="basicHttpBinding" maxReceivedMessageSize="2147483647">
                    <readerQuotas maxStringContentLength="2147483647" />
                    <security mode="TransportCredentialOnly">
                        <transport clientCredentialType="Windows" proxyCredentialType="None" />
                    </security>
                </binding>
            </basicHttpBinding>
            <netTcpBinding>
                <binding name="WindowsClientOverTcp" maxReceivedMessageSize="2147483647">
                    <readerQuotas maxStringContentLength="2147483647" />
                </binding>
            </netTcpBinding>
            <wsHttpBinding>
                <binding name="wsHttpBinding" maxReceivedMessageSize="2147483647">
                    <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
                      maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                </binding>
            </wsHttpBinding>
        </bindings>
        <behaviors>
            <serviceBehaviors>
                <behavior name="MyServiceBehaviors">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceAuthorization principalPermissionMode="UseWindowsGroups"
                      impersonateCallerForAllOperations="false" />
                    <serviceCredentials />
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>
</configuration>
abatishchev
  • 98,240
  • 88
  • 296
  • 433
M3NTA7
  • 1,307
  • 1
  • 13
  • 25
  • Is the assembly with the interface visible to the application? Also, did you specify the namespace as part of the interface name in the config file? – casperOne Mar 27 '09 at 23:10

13 Answers13

107

[ServiceContract] was missing in my case.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Leblanc Meneses
  • 3,001
  • 1
  • 23
  • 26
32

@Garry (a bit late, I know)

If your ServiceContract attribute defines a ConfigurationName, this should be the value in the endpoint, not the fully qualified name. I just had this problem now as described by the OP, and this was the solution for me. Hope this helps someone else who stumbles across this.

masty
  • 1,539
  • 1
  • 17
  • 20
  • 2
    This answer helped me solve my problem. The `ServiceContractAttribute` on the contract interface had defined values for `Name`, `Namespace` and `ConfigurationName`. I changed `name`, `bindingNamespace` and `contract` on the `endpoint` element in the web.config of the implementing service to match and the problem was solved. – John Mills Mar 18 '11 at 03:51
  • thanks for this, was banging my head off a brick wall for half an hour until I found this. – handles Nov 24 '11 at 12:21
  • renamed a configuration binding but ConfigurationName in the ServiceContract attribute and had this problem.. fixing the name conflict was the solution, hurray! – Erikest Mar 28 '12 at 23:21
13

This is a slightly more uncommon solution, that applied to my situation with the same error:

It's possible that the contract namespace can be overridden, with the following attribute:

[System.ServiceModel.ServiceContractAttribute([...], ConfigurationName = "IServiceSoap")]
public interface ISomeOtherServiceName

Which would require:

<endpoint address="" binding="basicHttpBinding" contract="IServiceSoap" />

Rather than the usual (namespace).ISomeOtherServiceName.

This can be a result of code generation, in my case WSCFBlue

Overflew
  • 7,872
  • 10
  • 45
  • 65
10

Your name attribute in the service element and the contract attribute in endpoint element are not correct. They need to be fully qualified names:

<service name="namespace.MyService">
      <endpoint contract="namespace.IMyService" >

Once you change the values to be fully qualified names that should resolve your error.

Rajesh
  • 7,766
  • 5
  • 22
  • 35
  • Wow, I had part somehow deleted [ServiceContract] and after correcting it, the IIS error message still showed that the endpoint should NOT be namespace qualified, and the service SHOULD. Gaah. Both qualified finally worked. – Jonas Apr 06 '18 at 14:46
8

Doesn't the contract attribute on the endpoint need to be the fully qualified namespace?

Garry
  • 1,291
  • 1
  • 11
  • 19
6

yes @Garry you are right. contract in endpoint should be fully qualified name

<endpoint binding="basicHttpBinding" bindingConfiguration="basicHttpBinding"      name="MyService" bindingName="basicHttpBinding" bindingNamespace="http://my.test.com"  contract="Namespace.IMyService">
Usman Masood
  • 1,937
  • 2
  • 17
  • 33
3

I have a habit of doing this ...

<system.serviceModel>
    <services>
      <service name="Service" behaviorConfiguration="wsHttpBehaviour">
        <endpoint 
            binding="wsHttpBinding" 
            contract="IService" 
            bindingConfiguration="wsHttpBinding" 
            />
        <endpoint contract="IService" binding="mexHttpBinding" address="mex" />
      </service>

when i should do this ...

<system.serviceModel>
    <services>
      <service name="namespace.Service" behaviorConfiguration="wsHttpBehaviour">
        <endpoint 
            binding="wsHttpBinding" 
            contract="namespace.IService" 
            bindingConfiguration="wsHttpBinding" 
            />
        <endpoint contract="namespace.IService" binding="mexHttpBinding" address="mex" />
      </service>

See what i mean ... It's the dumbest thing ever (especially when the app only has 1 or 2 items in it) but a "fully qualified" classname seems to make all the difference.

War
  • 8,539
  • 4
  • 46
  • 98
1

Using the visual studio 2013 "Add"->"Service" menu option created the web config sections for me but with the "endpoint" "contract" set to the name of the concrete class not the interface.

As soon as I corrected that all started working.

rob
  • 8,134
  • 8
  • 58
  • 68
1

I had the same error but the source of the problem was different. I was learning as I going and I first created a service using the Silverlight-enabled WCF service from the Silverlight templates in Visual Studio. I called this TerritoryService. When you create a service in this way the web.config is altered as below:

 <services>
      <service name="Services.TerritoryService">
        <endpoint address="" binding="customBinding" bindingConfiguration="Services.TerritoryService.customBinding0"
          contract="Services.TerritoryService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>

The examples that Im working off however use DomainServices.i.e. when using these you inherit from DomainService. So i deleted the TerritoryService I had created and then created a DomainService Class from the template off the Web templates menu in Visual Studio. I carried on working and everything compiled just fine. But when i ran it i got an error as per the title of this question.

The problem it turns out is that when you inherit from a domain service no such entry is created in the web.config file. It doesn't need it. But when you delete a service created via the Silverlight-enabled web service it does NOT delete the entry in the web.config file.

So because I had named both services the TerritoryService when the service was being called the entry in the web.config was pulled into play and the server went looking for a service defined in that manner which it could not find because i had deleted it.

So the solution was to simply delete the entry stubs as above that had been auto created by Visual Studio in the config file but not auto deleted by Visual Studio when i deleted the service. Once i did that the problem was resolved.

It took me a half hour to work this out though because of the naming "conflict". It "looked" very much right and was in line with many examples. So if you're inheriting from a domain service class you do not need/should not have an entry in the config file as you do when you've created a wcf service.

Community
  • 1
  • 1
rism
  • 11,932
  • 16
  • 76
  • 116
  • This one led me on the right path. I got this error after: 1) I created a normal WCF service (which updated my web.config). 2) Then I deleted that service. 3) Then I created a WCF Data Service with the same name. Removing the web.config change fixed me. – Josh Mouch Jan 04 '13 at 17:28
1

can you post code of your interface...? as normally this occurs if you haven't specified ServiceContract attribute in your Interface...

Usman Masood
  • 1,937
  • 2
  • 17
  • 33
1

In my case, the problem was a misnamed namespace. HTH

joseluisrod
  • 82
  • 1
  • 7
0

Ok, this doesn't really satisfy my question, but one way that I found to resolve it was to install .NET 3.5. because both of my other environments had 3.0.

So I really haven't determined why it would work in one environment and not the other, especially with that interface error.

Go figure?

M3NTA7
  • 1,307
  • 1
  • 13
  • 25
0

There's 2 mistakes in my case:

  1. The config sections are copied from another proxy project, and I forgot to change the namespace to full path.

  2. As a client, I copied the endpoint section into services node - the client is also a wcf service.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
flaugh
  • 1,517
  • 1
  • 10
  • 5