views:

354

answers:

2

I understand that I can make the property nullable or use a bool called [PropertyName]Specified to determine whether the property is serialized to XML, but I would like the auto-generated examples to hide these elements in one method's definition, and show them in another. This way the user knows whether they'll be there or not.

For example,

here is what displays now (same for both):

Web Service Method1 Example

...
<Object>
    <Column Value="int" xsi:nil="true" />
</Object>
...

Web Service Method2 Example

...
<Object>
    <Column Value="int" xsi:nil="true" />
</Object>
...

here is what I want to display:

Web Service Method1 Example

...
<Object>
    <Column Value="int" />
</Object>
...

Web Service Method2 Example

...
<Object />
...

Is this even possible without creating different Classes?

A: 

No, it's not. You're serializing instances of classes. This is independent of web methods.


The web service infrastructure doesn't fit what you're looking for. In WSDL, an operation uses messages which have parts which are of types which are described in an XML schema. In order for two operations to be the same except for one element (column), they must use messages referring to different types.

Alternatively, you could have one of your methods accept a parameter of a class without the extra column, and have the other use that same parameter, plus a separate parameter which is just the extra column.

John Saunders
It doesn't have to be independent. The methods on WebServices can have the XmlInclude attribute to determine which classes they (de)serialize. It could be possible that something exists for ignoring classes also. Unfortunate if it doesn't.
Adam A
XmlInclude on a method does not determine which classes they serialize. It indicates which classes should be exported to the WSDL. It's meant to describe the set of concrete classes, when the base type is used in the method signature.
John Saunders
Just want to add detail to this for anyone else who's looking: John is correct that each Web Service specifies the types it uses. These types are immutable between methods on that service (the same definition applies for all methods). The situation above SHOULD be possible if the methods are on DIFFERENT web services (since the types can be defined differently for each WSDL), but MSFT doesn't provide a useful way to do this (other than by subclassing), and it'd confuse wsdl.exe anyway.
Adam A
`wsdl.exe` is not relevant, as it is only used in the legacy ASMX web services, and not with WCF. What you're asking for isn't a lack in the Microsoft implementation - it's just the way that the web service standards work.
John Saunders
A: 

Best way, then, is just to have one class inherit the other and add the Column property.

Adam A