Ive noticed that if a field is specified as being not mandatory, when we generate the proxy class it will also generate an associated '[fieldname]IsSpecified' boolean related to that field. On using Fiddler to inspect the request, if the associated 'isSpecified' is set to false, this means that the field will not be sent over the wires.
我注意到如果一个字段被指定为非强制性的,当我们生成代理类时,它还将生成一个与该字段相关的“[fieldname] IsSpecified”布尔值。在使用Fiddler检查请求时,如果关联的'isSpecified'设置为false,则表示该字段不会通过连线发送。
I have two questions related to this
我有两个与此相关的问题
1.What is the point of this? Is it purely to minimize the amount of data being sent across the wire?
1.这有什么意义?是否纯粹是为了最大限度地减少通过线路发送的数据量?
2.If no value is passed into a parameter on a webservice, WCF will use the default data type for it. In the case of a integer field, the default will be 0. So once inside the method how is it possible to tell if this 0 is generated from nothing being sent from the client for that field, or if they indeed sent over a 0?
2.如果没有值传递给Web服务上的参数,WCF将使用默认数据类型。在整数字段的情况下,默认值为0.因此,一旦在方法内部,如何判断该0是否是从客户端为该字段发送的任何内容生成的,或者它们是否确实发送了0?
1 个解决方案
#1
4
On your question 2, the Specified
fields are not used only by the sending side. On the receiving side, the XML deserialiser will set the Specified
fields according to the presence or absence of the corresponding fields on the wire, which allows the service methods to find out whether they were actually transmitted.
在您的问题2上,指定字段不仅由发送方使用。在接收方,XML反序列化器将根据线路上相应字段的存在或不存在来设置指定字段,这允许服务方法找出它们是否实际传输。
As for why you would want to do this apart from compactness of wire representation, an example I've seen is a service which allows you to update several fields in a record at once. In addition to setting the expected non-null values for fields, the service uses different wire representations for two special cases:
至于为什么除了线表示的紧凑性之外你想要这样做,我看到的一个例子是允许你一次更新记录中的几个字段的服务。除了为字段设置预期的非空值之外,该服务还针对两种特殊情况使用不同的线表示:
-
Update this field to null:
<field1 xsi:nil="true" />
-
将此字段更新为null:
- Don't update this field: The XML element is omitted altogether.
- 不要更新此字段:完全省略XML元素。
#1
4
On your question 2, the Specified
fields are not used only by the sending side. On the receiving side, the XML deserialiser will set the Specified
fields according to the presence or absence of the corresponding fields on the wire, which allows the service methods to find out whether they were actually transmitted.
在您的问题2上,指定字段不仅由发送方使用。在接收方,XML反序列化器将根据线路上相应字段的存在或不存在来设置指定字段,这允许服务方法找出它们是否实际传输。
As for why you would want to do this apart from compactness of wire representation, an example I've seen is a service which allows you to update several fields in a record at once. In addition to setting the expected non-null values for fields, the service uses different wire representations for two special cases:
至于为什么除了线表示的紧凑性之外你想要这样做,我看到的一个例子是允许你一次更新记录中的几个字段的服务。除了为字段设置预期的非空值之外,该服务还针对两种特殊情况使用不同的线表示:
-
Update this field to null:
<field1 xsi:nil="true" />
-
将此字段更新为null:
- Don't update this field: The XML element is omitted altogether.
- 不要更新此字段:完全省略XML元素。