How to make changes to wcf service without breaking clients

来源:互联网 发布:淘宝清洗过期了怎么办 编辑:程序博客网 时间:2024/05/16 12:43

 

  在上一篇中讲解了,如何让一个WCF服务实现多个WCF数据契约,本篇介绍一个数据契约上的Name属性。先看一下,废话不多说,先看一下Demo。

  1、数据契约

<span style="font-family:SimSun;font-size:18px;">using System;using System.Collections.Generic;using System.Linq;using System.Runtime.Serialization;using System.ServiceModel;using System.Text;namespace HelloService{    // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的接口名“IHelloService”。    [ServiceContract(Name="IHello")]        public interface IHelloService    {        [OperationContract]        string GetMessage(string name);    }}</span>

  通过看上述DEMO估计看到了数据契约上方多出了一个Name的标签,那这是name标签是干什么的呢?

  我们看一下契约最终生成的WSDL文档。

<span style="font-family:SimSun;font-size:18px;">-<wsdl:portType name="Ihello">-<wsdl:operation name="GetMessage"><wsdl:input message="tns:Ihello_GetMessage_InputMessage" wsaw:Action="http://tempuri.org/Ihello/GetMessage"/><wsdl:output message="tns:Ihello_GetMessage_OutputMessage" wsaw:Action="http://tempuri.org/Ihello/GetMessageResponse"/></wsdl:operation></wsdl:portType></span>

  看到上述生成的Name标签,所以从这里我们可以了解到。name标签与WSDL文档中的portType name标签是一致的,而这个portType又作为一个客户端与WCF服务通信的一个接口。所以有了Name这个属性,当我们服务端中的数据契约如果改名称的话,利用这个Name属性就可以做到,在客户端不中断的情况下,更改数据契约。


  2、小结

        本篇简单的介绍了数据契约的一个Name属性,利用此属性就可以做到,在不中断客户端的情况下,更改数据契约。下一篇讲解:WCF数据契约和数据成员

 

0 0
原创粉丝点击