WCF:客户端配置中的合同“ X”与服务合同中的名称不匹配

FBryant87

当我尝试在VS中运行WCF服务时,此错误消息显示,并且我试图弄清楚它在“客户端配置”和“服务合同”中实际上指的是什么:

客户端配置中的合同“ IMyService”与服务合同中的名称不匹配

我认为服务合同部分是指:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace = "http://xxx/yyy", ConfigurationName = "IMyService")]
public interface IMyService
{
    // CODEGEN: Generating message contract since the operation MyService is neither RPC nor document wrapped.
    [System.ServiceModel.OperationContractAttribute(Action = "", ReplyAction = "*")]
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(Task))]
    SendResponse Request(SendRequest request);
}

关于客户端配置所指的任何想法

编辑:在我的web.config中,我有system.serviceModel的这一部分:

 <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="MyServiceBinding">
          <security mode="None" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="XXX.YYY.MyService">
        <endpoint binding="basicHttpBinding" bindingConfiguration="MyServiceBinding" name="MyServiceSendHttps"
          contract="IMyService" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost" />
          </baseAddresses>
        </host>
      </service>
    </services>
亚历山大·基谢列夫

请参阅项目中的app.config文件。如果您未通过编程方式配置客户端,则app.config文件必须包含客户端配置节点。

更新:您的第一个代码段包括以下行:

[System.ServiceModel.ServiceContractAttribute(Namespace = "http://xxx/yyy", ConfigurationName = "IMyService")]`.

在“ ConfigurationName”属性的文档中:https : //msdn.microsoft.com/zh-cn/library/system.servicemodel.servicecontractattribute.configurationname%28v=vs.110%29.aspx,我们可以阅读:

用于在应用程序配置文件中定位服务元素的名称。缺省值为服务实现类名称。

因此,我们有:服务实现类的名称为“ XXX.YYY.MyService”,并且(在第二个代码段中)我们看到“ <service name =“ XXX.YYY.MyService”>”,但属性的ConfigurationName值为“ IMyService”。 ”。

如果仅从行中删除“ ConfigurationName =“ IMyService”'

[System.ServiceModel.ServiceContractAttribute(Namespace = "http://xxx/yyy", ConfigurationName = "IMyService")]

像这样:

[System.ServiceModel.ServiceContractAttribute(Namespace = "http://xxx/yyy")]

应该可以解决这个问题。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章