svcutil.exe的 - 代理产生的不允许为空的字段不允许、字段、为空、svcutil

2023-09-04 00:26:26 作者:一世安稳

我试图使用Web服务使用WSDL通过使用svcutil.exe的创建WCF代理指定,但在WSDL指定的一些操作具有可选参数(的minOccurs =0),例如:

I am trying to consume a web service specified using WSDL by creating a WCF proxy using svcutil.exe, but the WSDL specifies that some of the operations have parameters that are optional (minOccurs="0"), for example:

<xs:element minOccurs="0" maxOccurs="1" name="meetingId" type="xs:int" />

不幸的是,生成的代理不容许我没有指定值(参数都不能为空),并且没有指定领域调用的一部分来指导,没有价值应该发送的代理。

Unfortunately, the generated proxy does not allow me to not specify the values (the parameters are not nullable), and there are no "specified" fields as part of the call to instruct the proxy that no value should be sent.

有没有办法使用SvcUtil工具来生成一个代理,让我做到这一点?

Is there any way to use svcutil to generate a proxy that would allow me to do this?

(在一个侧面说明,我通过我的研究,其他人可以使用添加服务引用功能,但对于正确地产生这些额外的指定字段注意到无论什么原因的Visual Studio似乎并不想生成之后,我添加引用代理(没有发生以后))

(On a side note, I noticed through my research that others were able to generate these extra "specified" fields correctly using the "Add Service Reference" feature, but for whatever reason Visual Studio doesn't appear to want to generate the proxy after I add the reference (nothing happen afterwards))

WSDL文件 生成的代理

用命令:SvcUtil工具的http:// SAS- int.elluminate.com/site/external/adapter/default/v1/webservice.wsdl /内部/n:*,Elluminate.WebService.WebServiceProxy /o:WebServiceProxy.cs /config:App.config / NOLOGO

Command Used: svcutil http://sas-int.elluminate.com/site/external/adapter/default/v1/webservice.wsdl /internal /n:*,Elluminate.WebService.WebServiceProxy /o:WebServiceProxy.cs /config:App.config /nologo

推荐答案

我猜SvcUtil工具按生成的客户端代理类有一个叫字段/属性 meetingId 类型 INT - 对不对?是的,这是不可为空 - 但我敢打赌,你也有一个布尔字段/属性名为 meetingIdSpecified - 仅当此设置为将服务实际上看它;如果不设置,则该服务不会看的价值,所以它几乎就像它放在 NULL

I would guess the client proxy class generated by svcutil has a field/property called meetingId of type int - right? Yes, this is non-nullable - but I bet you also have a boolean field/property called meetingIdSpecified - only if this is set to true will the service actually look at it; if you don't set it, then the service will not look at the value, so it's almost as if it where NULL.

此外 - 你没有指定字段为可以为空在你的XSD,要么 - 你指定它是可选的。为了使它可空,在这里使用的语法:

Also - you didn't specify the field to be nullable in your XSD, either - you specified it to be optional. To make it nullable, use this syntax here:

<xs:element minOccurs="0" maxOccurs="1" name="meetingId" type="xs:int" 
            nillable="true" />

见可空属性?这是用于制造领域真正为空的一个 - 你现在可以有这样的XML中的一个条目:

See the "nullable" attribute? That's the one used for making a field really nullable - you can now have an entry like this in your XML:

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <meetingId xsi:nil="true" />
</root>

马克·