Optional enumeration with WCF client

I work with an external provider web service that seems to be implemented in Java (I believe Apache Axis) and I consume it with a WCF client. Some operations require type enumeration input parameters. The problem is that they only want transfers to be transmitted in certain cases. Items are not marked as void in WSDL. Since they are listed, my WCF client will always pass the default value, even if it is not specified. This behavior causes an internal error in their maintenance.

Any thoughts on how to solve this problem? Preferably, this will be a solution that does not require manual modification of the proxy server, as this can lead to confusion if another developer had to generate it independently in the future.

The specific item is specified in the WSDL.

in the following way:
<xs:complexType name="complexTypeName"> <xs:sequence> <!-- More Stuff Here--> <xs:element minOccurs="0" name="parameterName" type="tns:parameterName" /> <!-- More Stuff Here--> </xs:sequence> </xs:complexType> <!-- . . . --> <xs:simpleType name="parameterName"> <xs:restriction base="xs:string"> <xs:enumeration value="ONLY_AVAILABLE_VALUE" /> </xs:restriction> </xs:simpleType> 

Svcutil translates this as

 [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.1")] [System.SerializableAttribute()] [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://vendorwebservicenamespace.com/")] public enum parameterName { /// <remarks/> ONLY_AVAILABLE_VALUE, } 

EDIT:. After some additional research, it seems that svcutil should usually generate optional parameters (minOccurs = 0) with the optional bool fieldNameSpecified parameter, which allows the caller to indicate the field should be serialized (this is described here , here , and here ).

In this case, however, the parameter is referenced as follows:

 [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://vendorservicenamespace.com/", Order=23)] [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] public Namespace.parameterName parameterName; 

When I try to manually add the appropriate fieldNameSpecified method, it does not seem to affect serialization (i.e. this parameter is still present in the soap message).

At this moment I wonder

  • Why doesn't svcutil include fieldNameSpecified parameters?
  • Why adding a parameter manually does not work?
  • Are there any other workarounds for this problem?

EDIT:. After even more research, I decided that part of the problem is the way WSDL is written. Provider WSDL does not match Schema reference for DataContractSerializer. Because of this, svcutil does not return to the XmlSerializer.

The problem is that it still creates message contracts for methods, but not data contracts. This seems to lead to a problem for any types that are not NULL by default, since they cannot be excluded from the message (can anyone confirm this?). Regardless of why the parameterNameSpecified method for XmlSerializer seems to be ignored when the parameter is labeled MessageBodyMemberAttribute (not sure why?)

The only way I was able to get around this behavior is to use the /wrapped option with svcutil. This leads to the fact that the contracts with messages are separated from the seralized parameters themselves. In this case, svcutil does generates parameterNameSpecified methods, and the XmlSerializer matches them.

+4
source share
1 answer

After investigating the problem, the only solution I could find was to create a proxy server using the / wrapped option on svcutil. As mentioned in the question above, this adds an extra layer of abstraction and allows the message content to exist a layer above the parameters. In this case, the XmlSerializer generates and matches the fieldNameSpecified properties.

+3
source

Source: https://habr.com/ru/post/1394203/


All Articles