本文介绍了在WCF函数重载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要实现的功能在WCF超载,但我不允许这样做。

I want to implement function overloading in WCF but i am not allowed to do so

    [OperationContract]
    [WebInvoke(Method = "GET",
    ResponseFormat = WebMessageFormat.Json)]
    branch_view[] GetBranches();

    [OperationContract]
    [WebInvoke(Method = "GET",
    ResponseFormat = WebMessageFormat.Json)]
    branch_view[] GetBranches(int pageNo , int pageSize);

我得到的错误是:

The error i got is:

不能有相同名称的同一合同两种操作,方法GetBranches和类型QHRService.IEntityService GetBranches违反此规则。您可以通过改变方法名或使用OperationContractAttribute的名称属性更改的操作之一的名称。

Cannot have two operations in the same contract with the same name, methods GetBranches and GetBranches in type QHRService.IEntityService violate this rule. You can change the name of one of the operations by changing the method name or by using the Name property of OperationContractAttribute.

为什么WCF不允许函数重载。

Why WCF does not allow Function overloading.

我可以改名字,让我的工作的功能,但任何理由?

I can change the name to get my function work but any reasons?

任何帮助是pciated AP $ P $

Any help is appreciated

推荐答案

WCF的设计是一个完全通用的通信框架 - 这意味着客户端可能不会基于.NET的,因此可能没有方法重载的任何理解。

WCF is designed to be a completely generic communications framework - which means that clients might not be .NET-based, and therefore might not have any understanding of method overloading.

有可用于具有相同名称的方法的功能,但它是一个痛苦得到可靠工作;我强烈建议只是咬咬牙,具有不同方法的名称,即使它感觉错误的。

There is functionality available for having methods with the same name, but it's a pain to get working reliably; I would strongly recommend just biting the bullet and having different method names, even though it feels 'wrong'.

这篇关于在WCF函数重载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 04:28