WCF Contract Name 'IMyService' could not be found?

后端 未结 13 2078
借酒劲吻你
借酒劲吻你 2021-02-01 01:16

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

相关标签:
13条回答
  • 2021-02-01 01:24

    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.

    0 讨论(0)
  • 2021-02-01 01:25

    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.

    0 讨论(0)
  • 2021-02-01 01:25

    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.

    0 讨论(0)
  • 2021-02-01 01:26

    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.

    0 讨论(0)
  • 2021-02-01 01:26

    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?

    0 讨论(0)
  • 2021-02-01 01:31

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

    0 讨论(0)
提交回复
热议问题