【问题标题】:Can't change wcf contract's method return values无法更改 wcf 合同的方法返回值
【发布时间】:2012-06-26 08:59:33
【问题描述】:

我正在构建一个 WCF 服务,我已经在 IService 文件中编写了合同并在服务文件中实现了它,当我尝试更改我声明的方法的任何返回值时就会出现问题,那就是因为它们被保存在CustomersService命名空间中的代码中,特别是在CustomersServiceClient类中,该类被锁定并且无法访问以进行更改。

这是我在 ICustomersService 文件中的代码:

 [ServiceContract]
    public interface ICustomersService
    {
        [OperationContract]
        CustomerDetails GetCustomerDetails(string customerid);
        [OperationContract]
        bool VerifyId(string customerid);
    }

以及 CustomersService 文件中的代码:

public CustomerDetails GetCustomerDetails(string customerid)
{
....
}
public bool VerifyId(string customerid)
{
...
}

在 CustomerService1 命名空间中,我已经生成并锁定了这段代码,因此任何修改我在 IService 中的方法的尝试都失败了,因为它被锁定在这里并且无法更改!

public class CustomersServiceClient : ClientBase<ICustomersService>, ICustomersService
    {
        public CustomersServiceClient();
        public CustomersServiceClient(string endpointConfigurationName);
        public CustomersServiceClient(Binding binding, EndpointAddress remoteAddress);
        public CustomersServiceClient(string endpointConfigurationName, EndpointAddress remoteAddress);
        public CustomersServiceClient(string endpointConfigurationName, string remoteAddress);

        public CustomerDetails GetCustomerDetails(string customerid);
        public bool VerifyId(string customerid);
    }

这对我来说是个严重的问题,希望你能找到我的答案。

【问题讨论】:

  • 请发布一些代码,显示您现在拥有什么以及您想要完成什么 - 很难理解您想要做什么。
  • 我会的,谢谢您的关注。

标签: wcf


【解决方案1】:

Web 服务比仅引用程序集稍微复杂一些。如果您更改服务接口,代理类代码不会自动更新。每次更改合同时都需要手动更新。

试试这个:

  1. 客户项目 -> 服务参考
  2. 选择您的参考 -> 鼠标右键
  3. 更新服务参考

如果您引用该程序集,WCF 还可以重用您的合同类型。在这种情况下,数据合同的更改将立即在客户端中看到。您可能会在该答案中找到实施步骤: How to use a custom type object at the client

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-20
    • 1970-01-01
    • 2015-09-24
    • 2012-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多