WCF Contract Name 'IMyService' could not be found?

后端 未结 13 2051
借酒劲吻你
借酒劲吻你 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:32

    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

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

    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.

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

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

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

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

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

    [ServiceContract] was missing in my case.

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

    @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.

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