绑定到具有可选值类型的SOAP服务 [英] Binding to a SOAP Service With Optional Value Types
问题描述
我有一个使用以下WSDL
生成的SOAP服务的方法:
I have a method on a SOAP service being generated with the following WSDL
:
<xs:complexType name="updateItem">
<xs:sequence>
<xs:element name="itemCode" type="xs:string" />
<xs:element minOccurs="0" name="itemParentCode" type="xs:string" />
<xs:element minOccurs="0" name="itemStatus" type="xs:string" />
<xs:element minOccurs="0" name="isActive" type="xs:boolean" />
<xs:element minOccurs="0" name="isPrimary" type="xs:boolean" />
</xs:sequence>
</xs:complexType>
我正在连接到此服务,并在.NET Framework 4.7桌面应用程序中使用Visual Studio生成客户端.
I'm connecting to this service and generating the client using Visual Studio in a .NET Framework 4.7 desktop application.
这将生成具有以下参数的方法:
This generates a method with the following parameters:
public void updateItem(string itemCode, string itemParentCode,
string itemStatus, bool isActive, bool isPrimary)
根据服务定义,isActive
和isPrimary
是可选参数,但是在生成的方法中,它们是不可为null的值类型.
According to the service definition, isActive
and isPrimary
are optional parameters, but in the generated method they are non-nullable value types.
是否有一种生成客户端的方法,以允许它们是可选的,也许是通过可为空的布尔值?
Is there a way to generate the client to allow these to be optional, perhaps via nullable booleans?
推荐答案
我终于找到了这个问题的答案,但是确实感觉默认行为是一个错误.在生成的Reference.svcmap
文档中,您可以添加<Wrapped>true</Wrapped>
以强制显示*Specified
字段.您必须在ClientOptions
节点下添加Wrapped
,如下所示:
I did finally find the answer to this question, but it does feel like the default behavior is a bug. In the generated Reference.svcmap
document, you can add a <Wrapped>true</Wrapped>
to force the *Specified
fields to show up. You must add Wrapped
under the ClientOptions
node, like so:
<ClientOptions>
<Wrapped>true</Wrapped>
</ClientOptions>
现在重新生成客户端将强制使用消息契约对象,因此调用现在将如下所示:
Regenerating the client now will force use of message contract objects, so the call will now look like this:
// Update an item
updateItem(new updateItem
{
itemCode = "testItem",
itemParentCode = "testParent",
itemStatus = "testStatus",
isActive = true,
isPrimary = true,
isActiveSpecified = true,
isPrimarySpecified = true
});
我对获得解决方案感到欣慰,但仍然认为这应该是生成消息合同以适应这种情况的默认方式.
I'm relieved to have the solution, but still think this should be the default way of generating message contracts to allow for this scenario.
这篇关于绑定到具有可选值类型的SOAP服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!