简体   繁体   English

更新WCF Web服务参考

[英]Update WCF Web Service Reference

I have a WCF SOAP service and recently changed the response of that method. 我有一个WCF SOAP服务,最近更改了该方法的响应。 I have other applications consuming this method. 我还有其他使用这种方法的应用程序。 I did not change the method name, parameters it accepts. 我没有更改方法名称及其接受的参数。 The only change I made is that I added 2 new properties to the response object. 我所做的唯一更改是,我向响应对象添加了2个新属性。 Explanation is as below, 解释如下

Method: 方法:

Public Class2 GetData(SampleClass1 data, bool extraStuffRequired)
{
    var obj = new Class2();
    //Process data here and load into obj
    return obj;
}

Definition of Class2 Before Change: 更改前Class2的定义:

Public class Class2
{
public string p1 {get; set;}
public string p2 {get; set;}
}

Definition of Class2 After Change: 更改后Class2的定义:

Public class Class2
{
public string p1 {get; set;}
public string p2 {get; set;}

public string p3 {get; set;}
public string p4 {get; set;}
}

Note that I have added 2 new properties p3 and p4 and based on busniess logic, i would either populate values in them or set them to empty string. 请注意,我已经添加了2个新属性p3和p4,并且基于商务逻辑,我要么在其中填充值,要么将它们设置为空字符串。

ConsumingApp1 wants these new properties so they update the service reference and get the classes generated and use the new properties(p3 and p4). ConsumingApp1需要这些新属性,以便它们更新服务引用并获取生成的类并使用新属性(p3和p4)。

ConsumingApp2 does not want them but they do call the method but only use p1 & p2. ConsumingApp2不需要它们,但是它们确实调用了该方法,但仅使用p1和p2。

My Question is, do I need to force ConsumingApp2 to update their service reference or would it actually work just fine without ConsumingApp2 making any changes ? 我的问题是,我是否需要强制ConsumingApp2更新他们的服务引用,或者在没有ConsumingApp2进行任何更改的情况下是否真的可以正常工作?

No , ConsumingApp2 should be fine without updating the Service Reference. ,ConsumingApp2应该没有更新服务参考就可以了。 So, Missing values for p3, p4 would be initialized to default value. 因此,p3,p4的缺失值将被初始化为默认值。 In your case, since p3, p4 are of type String, they would be initialized to null. 在您的情况下,由于p3,p4的类型为String,因此它们将被初始化为null。

For DataContract Version rule are following 遵循DataContract版本规则

  1. If you Add new non-required members, then Client would remain unaffected and Missing values are initialized to defaults. 如果添加新的非必需成员,则客户端将保持不受影响,并且缺失值将初始化为默认值。

  2. If you Add new required members, then Client would be affected and Exception is thrown. 如果添加新的必需成员,则客户端将受到影响并引发异常。

A screenshot summarizing From [MSDN]. 屏幕快照总结自[MSDN]。 1 Also you can read more about Service Versioning & Versioning Strategy 1您还可以阅读有关服务版本控制版本控制策略的更多信息 在此处输入图片说明

Note: In your posted question, you haven't declared any DataContract or DataMember for the datatypes. 注意:在您发布的问题中,您尚未为数据类型声明任何DataContract或DataMember。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM