删除 nill="True"来自 WCF 请求 [英] Removing nill="True" from WCF Request
问题描述
我在我的应用程序中使用 WCF web 服务,同时我正在发送请求,我正在使用 fiddler 监视请求和响应.问题是对于空标签,wcf 客户端生成 nil=true
属性.无论如何我可以将它们更改为空白标签吗?这是例子
I am using a WCF webservice in my application, while i am sending a request im monitoring the request and responses with fiddler. the problem is for null tags, wcf client generates nil=true
attribute. is there anyway i could change the them to blank tags ?
here is the example
<a:Seats i:nil="true" />
这是座位类的列表,它是可选的标签,所以没有必要传递它.但是,当我发送上述请求时,我会收到来自 Web 服务的 Object reference not set to an instance of an object
响应.我被要求从请求中删除 nill 属性.所以它必须变成这样
which is list of Seat class, it is optional tag so it is not necessary to pass it. but when i send a request like above i receive Object reference not set to an instance of an object
response from the web service. i have been asked to remove the nill attribute from the request. so it must become like this
<a:Seats/>
添加 EmitDefaultValue=false
将完全删除标签,因此它不是答案.我怎样才能做到这一点 ?
Adding EmitDefaultValue=false
will remove the tag completely so it is not the answer. how can i do that ?
推荐答案
我自己想出来的,
我重新配置了ServiceReference并将集合类型更改为System.Collection.Generic.List
(起初是System.Array
)
I Re-Configure the ServiceReference and changed the collection type to System.Collection.Generic.List
(at first it was System.Array
)
然后当我想发出请求时,只需像下面这样初始化请求对象
then when i want to make the request simply initialize the request object like below
rq.Seats = new List<Seat>(); // result <a:Seats/>
我知道它很奇怪,但是当它是数组时,结果就不一样了
I know its strange but when it was array the result was different
rq.Seats = new seat[] { } ; //result <a:Seats nil="true" />
这篇关于删除 nill="True"来自 WCF 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!