[英]WCF: The contract 'X' in client configuration does not match the name in service contract
当我尝试在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>
我遇到了同样的问题,我花了很多时间寻找解决方案。 然后,我发现了有关WCF工具svcutil.exe生成的代码的本文 。
不能保证生成的C#代码也适用于服务端合同。 就我而言,问题出在ReplyAction =“ *”(在问题中我也看到了)。 根据MSDN文档 :
在服务中指定一个星号会指示WCF不要在消息中添加回复动作,如果您直接针对消息进行编程,这将非常有用。
变更后
[System.ServiceModel.OperationContractAttribute(Action = "", ReplyAction = "*")]
至
[System.ServiceModel.OperationContractAttribute(Action = "")]
问题解决了。
请参阅项目中的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")]
应该可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.