无法找到WCF合同名称'IMyService'?

时间:2009-03-27 22:56:40

标签: .net wcf exception-handling

  

在服务'MyService'实施的合同列表中找不到合同名称'IMyService'.. ---> System.InvalidOperationException:在服务“MyService”实现的合同列表中找不到合同名称“IMyService”。

这让我发疯了。我有一个WCF Web服务,可以在我的开发机器上运行,但是当我将它复制到我用于测试的虚拟机时,我得到的错误似乎表明我没有实现接口,但它没有感觉因为该服务在我的Windows XP IIS上运行。虚拟机使用Windows Server 2003 IIS。有什么想法吗?

这里需要注意的一点是,即使只是尝试在Web浏览器中作为客户端访问服务,我也会在VM上出现此错误。

注意:我使用的是principalPermissionMode =“UseWindowsGroups”,但这不是我本地计算机上的问题。我只是将自己添加到适当的Windows组。但我的VM没有运气。

配置:

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

14 个答案:

答案 0 :(得分:103)

[ServiceContract]在我的案例中失踪了。

答案 1 :(得分:32)

@Garry(有点晚了,我知道)

如果ServiceContract属性定义了ConfigurationName,则它应该是端点中的值,而不是完全限定名称。我现在就像OP所描述的那样遇到了这个问题,这对我来说就是解决方案。希望这可以帮助其他人偶然发现这一点。

答案 2 :(得分:13)

这是一个稍微不常见的解决方案,适用于我的情况并出现同样的错误:

可以使用以下属性覆盖合同命名空间:

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

需要:

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

而不是通常的(命名空间).ISomeOtherServiceName

这可能是代码生成的结果,在我的情况下WSCFBlue

答案 3 :(得分:9)

service元素中的name属性和endpoint元素中的contract属性不正确。他们需要完全合格的名字:

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

将值更改为应解决错误的完全限定名称。

答案 4 :(得分:8)

端点上的contract属性是否需要是完全限定的命名空间?

答案 5 :(得分:6)

是的@Garry你是对的。 端点中的契约应该是完全限定名称

<endpoint binding="basicHttpBinding" bindingConfiguration="basicHttpBinding"      name="MyService" bindingName="basicHttpBinding" bindingNamespace="http://my.test.com"  contract="Namespace.IMyService">

答案 6 :(得分:3)

我习惯这样做......

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

我应该这样做......

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

看看我的意思...... 这是有史以来最蠢的事情(特别是当应用程序中只有1或2个项目时),但“完全合格”的类名似乎有所不同。

答案 7 :(得分:1)

你可以发布你的界面代码......? 通常,如果您未在接口中指定ServiceContract属性,则会发生这种情况......

答案 8 :(得分:1)

我有同样的错误,但问题的根源不同。我正在学习,我首先使用Visual Studio中Silverlight模板启用Silverlight的WCF服务创建服务。我打电话给这个TerritoryService。以这种方式创建服务时,web.config将更改如下:

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

我正在使用的示例使用DomainServices.i.e。使用这些时,您继承自DomainService。所以我删除了我创建的TerritoryService,然后从Visual Studio中的Web模板菜单中的模板创建了一个DomainService类。我继续工作,所有编译都很好。但是当我运行它时,根据这个问题的标题我得到了一个错误。

结果表明,当您从域服务继承时,在web.config文件中不会创建此类条目。它不需要它。但是当您删除通过启用Silverlight的Web服务创建的服务时,它不会删除web.config文件中的条目。

因为我在调用服务时将两个服务命名为TerritoryService,所以web.config中的条目被启动并且服务器寻找以这种方式定义的服务,因为我已经删除了它找不到的服务它

因此,解决方案是简单地删除上面的条目存根,这些存根是由Visual Studio在配置文件中自动创建的,但在删除服务时不会被Visual Studio自动删除。一旦我这样做,问题就解决了。

由于命名“冲突”,我花了半个小时来解决这个问题。它“看起来”非常正确,与许多例子一致。因此,如果您从域服务类继承,则不需要/不应该像创建wcf服务时那样在配置文件中创建条目。

答案 9 :(得分:1)

就我而言,问题是一个名不副实的命名空间。 HTH

答案 10 :(得分:1)

使用visual studio 2013“添加” - &gt;“服务”菜单选项为我创建了Web配置部分,但将“端点”“契约”设置为具体类的名称而不是接口。

一旦我纠正,一切都开始起作用了。

答案 11 :(得分:0)

您是否在IIS中的VM上设置了任何身份验证?尝试将其设置为匿名,看看它是否运行。

答案 12 :(得分:0)

好的,这并不能真正满足我的问题,但我发现解决它的一种方法是安装.NET 3.5。因为我的其他两个环境都有3.0。

所以我真的没有确定它为什么会在一个环境中工作而不是另一个环境,尤其是那个接口错误。

去图?

答案 13 :(得分:0)

我的案子有2个错误:

  1. 配置部分是从另一个代理项目复制的,我忘了将命名空间更改为完整路径。

  2. 作为客户端,我将端点部分复制到服务节点 - 客户端也是一个wcf服务。