我是新手,但是读了一些关于wcf的文章后我才知道,如果您更改ServcieContrcat,则不仅必须更改服务端,还必须更改客户端,这真的很难管理。
Example 1:
开发人员必须创建WCF服务以进行订单处理,并具有以下功能:GetOrderById,GetOrdersByStatus,SaveOrder
ServiceContract可能如下所示
[ServiceContract]
public interface IOrderService
{
[OperationContract]
Order GetOrderById(int orderId);
[OperationContract]
List<Order> GetOrdersByStatus(OrderStatus orderStatus);
[OperationContract]
void SaveOrder(Order order)
}
例如,一个月后,项目经理说:好吧,我们的客户需要另一个功能:DeleteOrderById,GetOrdersByCustomerId,不再需要GetOrdersByStatus,我们需要GetOrdersByStatusAndCustomerId
开发人员必须更新ServiceContrcat并更新客户端。如您所见,ServiceContrcat中的任何更改都非常困难
因此,我正在寻求有关如何开发wcf服务的最佳指导,如果我们扩展功能或进行任何类型的更改,不会产生任何问题,但是客户端不会遇到任何问题。谢谢
我遇到了同样的问题,基本上是对方法的永久更改,这些更改会破坏客户端上的接口。
This is what I did: All of my 30+ functions (and the list grows and grows) took strings, ints and bytes() as data types as both input and output parameters, I created a master single endpoint and function that receives, as an input parameter, and sends back as the output, a single simple class. This class, called HostInterface, contains just two parameters, a string (which I use to encapsulate all my strings and ints) and a byte() array (into which I stuff all my binaries)
So, whether a client is calling something simple like Ping() with just one string param, or something complicated like ResumeDownload() with 5 strings, 2 ints and a byte array, all of those parameters get encapsulated in my HostInterface class, the strings and ints into the one String parameters (as XML) and the bytes into the byte field.
在主机端收到请求后,请按以下步骤进行:
Function HostConnect(byval objInbound as HostInterface) as HostInterface
我解压缩objInbound中的字符串参数,将XML更改为对象,然后解压缩字节并将其添加到同一对象的字节部分。然后,我检查方法名称(ping或ResumeDownload)并进行相应处理。下图显示了基本思想-所有功能都通过单个函数进行操作,该函数采用并发送与参数相同的简单类。因此,我的界面无需更改。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句