【问题标题】:Contract attribute is invalid合约属性无效
【发布时间】:2023-03-03 06:59:25
【问题描述】:

我已经达到了几个小时了。我收到此错误消息:

“合同”属性无效 - 值“AddressService.IAddressVerificationService”根据其数据类型“clientContractType”无效 - 枚举约束失败。

配置文件如下所示:

<endpoint address="http://www.verifythisaddress.com/AddressVerification/AddressVerificationService.svc"
           binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAddressVerificationService"
           contract="AddressService.IAddressVerificationService" name="BasicHttpBinding_IAddressVerificationService" />

我的服务开始看起来像:

namespace AddressVerificationWCF
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.

[ServiceContract]
public interface IAddressVerificationService
{
    [OperationContract]
    Address VerifyThisAddress(string stuff);
}

}

我尝试了很多方法,例如更改名称、删除文件等,但我又摸不着头脑了。 谢谢。

【问题讨论】:

    标签: wcf web-config


    【解决方案1】:

    合约需要是接口的完全限定名称——通常是包含接口的命名空间,加上接口名称。查看您发布的代码,这应该是:

    AddressVerificationWCF.IAddressVerificationService
    

    所以你的配置看起来像:

    <endpoint address="http://www.verifythisaddress.com/AddressVerification/AddressVerificationService.svc"
              binding="basicHttpBinding"
              bindingConfiguration="BasicHttpBinding_IAddressVerificationService"
              contract="AddressVerificationWCF.IAddressVerificationService"
              name="BasicHttpBinding_IAddressVerificationService" />
    

    【讨论】:

    • 谢谢,但我认为这不仅仅是因为它是如何编译的。我认为我最好这样做,但是,我现在遇到了一个新错误。可能是IIS问题? stackoverflow.com/questions/22283787/…
    • "合约需要是接口的全名" - 实际上需要是ServiceContractAttribute.ConfigurationName,默认是接口的全名,但也可以是被覆盖。
    【解决方案2】:

    The value is invalid according to its datatype 'clientcontracttype'

    在上面文森特范登伯格提出的下面解决了我的问题。归功于文森特...

    当您在项目中缺少引用时会发生同样的错误 使用 .config] 到包含 接口/服务合约...

    【讨论】:

      【解决方案3】:

      我遇到了类似的问题。我在管理员模式下运行了我的 VS 2012,它解决了它。

      【讨论】:

        猜你喜欢
        • 2012-09-06
        • 2017-11-30
        • 2023-03-13
        • 2019-04-19
        • 1970-01-01
        • 1970-01-01
        • 2016-12-05
        • 2014-07-15
        • 1970-01-01
        相关资源
        最近更新 更多