.net 找不到 WCF 合同名称“IMyService”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/691746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WCF Contract Name 'IMyService' could not be found?
提问by M3NTA7
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'.
在服务“MyService”实现的合同列表中找不到合同名称“IMyService”.. ---> System.InvalidOperationException:在由服务实现的合同列表中找不到合同名称“IMyService”服务“我的服务”。
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?
这真让我抓狂。我有一个 WCF Web 服务可以在我的开发机器上运行,但是当我将它复制到我用于测试的虚拟机时,我收到似乎表明我没有实现接口的错误,但它没有感觉是因为该服务在我的 windows xp IIS 上工作。虚拟机使用 Windows Server 2003 IIS。有任何想法吗?
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.
这里要注意的一件事是,即使只是尝试在 Web 浏览器中作为客户端访问该服务,我的 VM 上也会出现此错误。
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.
注意:我使用的是 principalPermissionMode="UseWindowsGroups",但这在我的本地机器上不是问题。我只是将自己添加到相应的 Windows 组中。但我的虚拟机没有运气。
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>
回答by Leblanc Meneses
[ServiceContract]was missing in my case.
[ServiceContract]在我的情况下丢失了。
回答by masty
@Garry (a bit late, I know)
@Garry(有点晚了,我知道)
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.
如果您的 ServiceContract 属性定义了 ConfigurationName,则这应该是端点中的值,而不是完全限定名称。正如 OP 所描述的那样,我现在遇到了这个问题,这就是我的解决方案。希望这可以帮助其他偶然发现此问题的人。
回答by Overflew
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.
而不是通常的(namespace).ISomeOtherServiceName。
This can be a result of code generation, in my case WSCFBlue
这可能是代码生成的结果,在我的情况下是WSCFBlue
回答by Rajesh
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 属性和 endpoint 元素中的 contract 属性不正确。它们需要是完全限定的名称:
<service name="namespace.MyService">
<endpoint contract="namespace.IMyService" >
Once you change the values to be fully qualified names that should resolve your error.
一旦您将值更改为应该可以解决您的错误的完全限定名称。
回答by Garry
Doesn't the contract attribute on the endpoint need to be the fully qualified namespace?
端点上的合同属性不需要是完全限定的命名空间吗?
回答by Usman Masood
yes @Garry you are right. contract in endpoint should be fully qualified name
是的@Garry 你是对的。端点中的合同应该是完全限定名称
<endpoint binding="basicHttpBinding" bindingConfiguration="basicHttpBinding" name="MyService" bindingName="basicHttpBinding" bindingNamespace="http://my.test.com" contract="Namespace.IMyService">
回答by War
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.
明白我的意思……这是有史以来最愚蠢的事情(尤其是当应用程序中只有 1 或 2 个项目时),但“完全限定”类名似乎使一切变得不同。
回答by joseluisrod
In my case, the problem was a misnamed namespace. HTH
就我而言,问题是命名空间命名错误。HTH
回答by rob
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.
使用 Visual Studio 2013“添加”->“服务”菜单选项为我创建了 web 配置部分,但将“端点”“合同”设置为具体类的名称而不是接口。
As soon as I corrected that all started working.
我一纠正,一切都开始工作了。
回答by Usman Masood
can you post code of your interface...? as normally this occurs if you haven't specified ServiceContract attribute in your Interface...
你可以发布你的界面代码......?如果您没有在接口中指定 ServiceContract 属性,通常会发生这种情况......

