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

M3N*_*TA7 50 .net wcf exception-handling

服务'MyService'实现的合同列表中找不到合同名称'IMyService'.. ---> System.InvalidOperationException:在合同列表中找不到合同名称'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>
Run Code Online (Sandbox Code Playgroud)

Leb*_*ses 103

[ServiceContract] 在我的情况下失踪了.

  • 哎呀!!!! 该死的一切都是地狱,......我每次都被这个时间所困扰!谢谢 :-) (6认同)

mas*_*sty 32

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

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

  • 这个答案帮助我解决了我的问题.契约接口上的`ServiceContractAttribute`定义了`Name`,`Namespace`和`ConfigurationName`的值.我在实现服务的web.config中的`endpoint`元素上更改了`name`,`bindingNamespace`和`contract`以匹配问题并解决了问题. (2认同)

Ove*_*lew 13

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

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

[System.ServiceModel.ServiceContractAttribute([...], ConfigurationName = "IServiceSoap")]
public interface ISomeOtherServiceName
Run Code Online (Sandbox Code Playgroud)

这需要:

<endpoint address="" binding="basicHttpBinding" contract="IServiceSoap" />
Run Code Online (Sandbox Code Playgroud)

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

这可能是代码生成的结果,在我的例子中是WSCFBlue


Raj*_*esh 9

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

<service name="namespace.MyService">
      <endpoint contract="namespace.IMyService" >
Run Code Online (Sandbox Code Playgroud)

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


Gar*_*rry 8

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

  • 这也是我的问题的解决方案.令人困惑的是,许多在线示例都没有包含命名空间. (2认同)

Usm*_*ood 6

是的,加里你是对的.端点中的契约应该是完全限定的名称

<endpoint binding="basicHttpBinding" bindingConfiguration="basicHttpBinding"      name="MyService" bindingName="basicHttpBinding" bindingNamespace="http://my.test.com"  contract="Namespace.IMyService">
Run Code Online (Sandbox Code Playgroud)


M3N*_*TA7 0

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

所以我真的还没有确定为什么它可以在一种环境中工作而不能在另一种环境中工作,尤其是在出现接口错误的情况下。

去搞清楚?