svcutil.exe - Proxy generated not allowing for nullable fields

前端 未结 3 941
鱼传尺愫
鱼传尺愫 2021-01-01 00:19

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

相关标签:
3条回答
  • 2021-01-01 00:34

    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.

    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" />
    

    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>
    

    Marc

    0 讨论(0)
  • 2021-01-01 00:35

    Do not use SVCUtil if it does not work for you. If the service is not very complicated, you can try writing the service interface manually, and use ChannelFactory<> to create your proxies.

    0 讨论(0)
  • 2021-01-01 00:35

    It is a problem because minOccurs="0" should allow you not to emit the 'meetingId' value, and the generated proxy does not allow it.

    You only consume the service, so you don't have control over the wsdl and you cannot add nillable="true" in the wsdl in order to have 'meetingId' optional in your proxy.

    If you generate your proxy with wsdl.exe, and not svcutil.exe, you will have the additional field 'meetingIdSpecified' that allows you to choose whether or not to emit the field meetingId.

    wsdl.exe http:///myservice?wsdl
    

    But with wsdl.exe you will consume your service with asp.net web service, and not WCF.

    I think the missing field is a bug in svcutil.exe (for me 4.0.30319.17929), because if you generate with the option /wrapped:

    svcutil.exe /wrapped http:///myservice?wsdl
    

    ..then you will also have the field 'meetingIdSpecified' generated !

    0 讨论(0)
提交回复
热议问题