472,982 Members | 2,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,982 software developers and data experts.

Polymorphic return values

I am trying to return one of two different objects from the same
method, but I can not do it in WSDL or C#.

I have a web service with three methods.

I have been told that one of the methods must return either <Respuesta
....> or <ConfirmacionPeticion ...> directly under the SOAP Body. Other
methods are already capable of returning just <Respuesta ...> or just
<ConfirmacionPeticion ...>. What is new is one method being capable of
returning both types.

I have been modifying over one of the previous methods:

[WebMethodAttribute( Description = "Blah...")]
[SoapDocumentMethod( ourMethodNamespace, Use = SoapBindingUse.Literal,
ParameterStyle = SoapParameterStyle.Bare)]
[return: XmlElement( Respuesta.Marca, Namespace =
Respuesta.EspacioNombres)]
public Respuesta solicitaRespuestaAsincrona( ...)

The obvious thing is to substitute the return type by object:

[WebMethodAttribute( Description = "Blah...")]
[SoapDocumentMethod( ourMethodNamespace, Use = SoapBindingUse.Literal,
ParameterStyle = SoapParameterStyle.Bare)]
public object solicitaRespuestaAsincrona( ...)

But then the automatic WSDL becomes:

<wsdl:message name="solicitaRespuestaAsincronaSoapOut">
<wsdl:part name="solicitaRespuestaAsincronaResult"
element="tns:solicitaRespuestaAsincronaResult"/>
</wsdl:message>

That is, under <soap:Body> I get a <solicitaRespuestaAsincronaResult>
element followed by the members of the actual object being returned.
This is not what I want, I want either <Respuesta> or
<ConfirmacionRespuesta>.

I then tried to have several XML return attributes:

[WebMethodAttribute( Description = "Blah...")]
[SoapDocumentMethod( ourMethodNamespace, Use = SoapBindingUse.Literal,
ParameterStyle = SoapParameterStyle.Bare)
[return:
XmlElement( Respuesta.Marca,
Namespace = Respuesta.EspacioNombres),
XmlElement( ConfirmacionPeticion.Marca,
Namespace = ConfirmacionPeticion.EspacioNombres)]]
public object solicitaRespuestaAsincrona( ...)

but then I get:

System.InvalidOperationException: You need to add
XmlChoiceIdentifierAttribute to the 'solicitaRespuestaAsincronaResult'
member.
I then tried the inverse route of hacking the WSDL. I created a new
type:

<wsdl:types>
....
<!-- Since this does not have a namespace, this breaks the Basic
Profile. -->
<s:schema elementFormDefault="qualified">
<s:complexType name="RespuestaOConfirmacion" >
<s:sequence>
<s:choice minOccurs="0" maxOccurs="1">
<s:element minOccurs="1" maxOccurs="1" name="Respuesta" />
<s:element minOccurs="1" maxOccurs="1"
name="ConfirmacionPeticion" />
</s:choice>
</s:sequence>
</s:complexType>
<!-- Without an explicit element:
// CODEGEN: The operation binding 'solicitaRespuestaAsincrona'
from
namespace 'http://www.map.es/scsp/' was ignored.
Specifying a type for use=literal messages is not supported.
Type name='RespuestaOConfirmacion' from targetNamespace=''
cannot be used as top-level any element.-->
<s:element name="RespuestaOConfirmacion"
type="RespuestaOConfirmacion"/>
</s:schema>
</wsdl:types>

and

<wsdl:message name="solicitaRespuestaAsincronaSoapOut">
<wsdl:part name="solicitaRespuestaAsincronaResult"
element="RespuestaOConfirmacion"/>
</wsdl:message>

This type is stubbed as

public partial class RespuestaOConfirmacion
{
[XmlElement("ConfirmacionPeticion", typeof(ConfirmacionPeticion))]
[XmlElement("Respuesta", typeof(Respuesta))]
[XmlChoiceIdentifier("nombreElemento")]
public object unaRespuestaOUnaConfirmacion;

[System.Xml.Serialization.XmlIgnoreAttribute()]
public RespuestaOConfirmacionEleccion nombreElemento;
}

[System.Xml.Serialization.XmlTypeAttribute(IncludeI nSchema =
false)]
public enum
RespuestaOConfirmacionEleccion
{
ConfirmacionPeticion,
Respuesta
}
I then tried with:

....
[return:
XmlChoiceIdentifier(MemberName = "nombreElemento"),
XmlElement( Respuesta.Marca,
Namespace = Respuesta.EspacioNombres),
XmlElement( ConfirmacionPeticion.Marca,
Namespace = ConfirmacionPeticion.EspacioNombres)]
public RespuestaOConfirmacion solicitaRespuestaAsincrona( ...)

This causes:

System.InvalidOperationException: There was an error reflecting
'solicitaRespuestaAsincronaResult'. --->
System.InvalidOperationException: Missing 'nombreElemento' member
needed for serialization of choice 'solicitaRespuestaAsincronaResult'.

in spite of me assigning a value to the nombreElemento field in the
return value.

If I have

[return:
XmlChoiceIdentifier(MemberName = "nombreElemento"),
XmlElement( Respuesta.Marca,
Namespace = Respuesta.EspacioNombres),
XmlElement( ConfirmacionPeticion.Marca,
Namespace = ConfirmacionPeticion.EspacioNombres)]
[return: XmlElement("RespuestaOConfirmacion", Namespace = "")]

the return value is serialized as
<RespuestaOConfirmacion>
<Respuesta ...>
....
</RespuestaOConfirmacion>

That is, the Respuesta or the ConfrimacionPeticion are wrapped with
<RespuestaOConfirmacion> which again is not what I want.
So summarizing, how do you express either in C# or in WSDL that you can
return any of two different elements under <soap:Body>?

Thanks in advance.
--
David Mediavilla

Jan 23 '06 #1
2 5512
My advice u to use a union for multiple return types...

--
HTH

Thanks,
Yunus Emre ALP÷ZEN
BSc, MCSD.NET
Microsoft .NET & Security MVP

<6k*******@sneakemail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I am trying to return one of two different objects from the same
method, but I can not do it in WSDL or C#.

I have a web service with three methods.

I have been told that one of the methods must return either <Respuesta
...> or <ConfirmacionPeticion ...> directly under the SOAP Body. Other
methods are already capable of returning just <Respuesta ...> or just
<ConfirmacionPeticion ...>. What is new is one method being capable of
returning both types.

I have been modifying over one of the previous methods:

[WebMethodAttribute( Description = "Blah...")]
[SoapDocumentMethod( ourMethodNamespace, Use = SoapBindingUse.Literal,
ParameterStyle = SoapParameterStyle.Bare)]
[return: XmlElement( Respuesta.Marca, Namespace =
Respuesta.EspacioNombres)]
public Respuesta solicitaRespuestaAsincrona( ...)

The obvious thing is to substitute the return type by object:

[WebMethodAttribute( Description = "Blah...")]
[SoapDocumentMethod( ourMethodNamespace, Use = SoapBindingUse.Literal,
ParameterStyle = SoapParameterStyle.Bare)]
public object solicitaRespuestaAsincrona( ...)

But then the automatic WSDL becomes:

<wsdl:message name="solicitaRespuestaAsincronaSoapOut">
<wsdl:part name="solicitaRespuestaAsincronaResult"
element="tns:solicitaRespuestaAsincronaResult"/>
</wsdl:message>

That is, under <soap:Body> I get a <solicitaRespuestaAsincronaResult>
element followed by the members of the actual object being returned.
This is not what I want, I want either <Respuesta> or
<ConfirmacionRespuesta>.

I then tried to have several XML return attributes:

[WebMethodAttribute( Description = "Blah...")]
[SoapDocumentMethod( ourMethodNamespace, Use = SoapBindingUse.Literal,
ParameterStyle = SoapParameterStyle.Bare)
[return:
XmlElement( Respuesta.Marca,
Namespace = Respuesta.EspacioNombres),
XmlElement( ConfirmacionPeticion.Marca,
Namespace = ConfirmacionPeticion.EspacioNombres)]]
public object solicitaRespuestaAsincrona( ...)

but then I get:

System.InvalidOperationException: You need to add
XmlChoiceIdentifierAttribute to the 'solicitaRespuestaAsincronaResult'
member.
I then tried the inverse route of hacking the WSDL. I created a new
type:

<wsdl:types>
...
<!-- Since this does not have a namespace, this breaks the Basic
Profile. -->
<s:schema elementFormDefault="qualified">
<s:complexType name="RespuestaOConfirmacion" >
<s:sequence>
<s:choice minOccurs="0" maxOccurs="1">
<s:element minOccurs="1" maxOccurs="1" name="Respuesta" />
<s:element minOccurs="1" maxOccurs="1"
name="ConfirmacionPeticion" />
</s:choice>
</s:sequence>
</s:complexType>
<!-- Without an explicit element:
// CODEGEN: The operation binding 'solicitaRespuestaAsincrona'
from
namespace 'http://www.map.es/scsp/' was ignored.
Specifying a type for use=literal messages is not supported.
Type name='RespuestaOConfirmacion' from targetNamespace=''
cannot be used as top-level any element.-->
<s:element name="RespuestaOConfirmacion"
type="RespuestaOConfirmacion"/>
</s:schema>
</wsdl:types>

and

<wsdl:message name="solicitaRespuestaAsincronaSoapOut">
<wsdl:part name="solicitaRespuestaAsincronaResult"
element="RespuestaOConfirmacion"/>
</wsdl:message>

This type is stubbed as

public partial class RespuestaOConfirmacion
{
[XmlElement("ConfirmacionPeticion", typeof(ConfirmacionPeticion))]
[XmlElement("Respuesta", typeof(Respuesta))]
[XmlChoiceIdentifier("nombreElemento")]
public object unaRespuestaOUnaConfirmacion;

[System.Xml.Serialization.XmlIgnoreAttribute()]
public RespuestaOConfirmacionEleccion nombreElemento;
}

[System.Xml.Serialization.XmlTypeAttribute(IncludeI nSchema =
false)]
public enum
RespuestaOConfirmacionEleccion
{
ConfirmacionPeticion,
Respuesta
}
I then tried with:

...
[return:
XmlChoiceIdentifier(MemberName = "nombreElemento"),
XmlElement( Respuesta.Marca,
Namespace = Respuesta.EspacioNombres),
XmlElement( ConfirmacionPeticion.Marca,
Namespace = ConfirmacionPeticion.EspacioNombres)]
public RespuestaOConfirmacion solicitaRespuestaAsincrona( ...)

This causes:

System.InvalidOperationException: There was an error reflecting
'solicitaRespuestaAsincronaResult'. --->
System.InvalidOperationException: Missing 'nombreElemento' member
needed for serialization of choice 'solicitaRespuestaAsincronaResult'.

in spite of me assigning a value to the nombreElemento field in the
return value.

If I have

[return:
XmlChoiceIdentifier(MemberName = "nombreElemento"),
XmlElement( Respuesta.Marca,
Namespace = Respuesta.EspacioNombres),
XmlElement( ConfirmacionPeticion.Marca,
Namespace = ConfirmacionPeticion.EspacioNombres)]
[return: XmlElement("RespuestaOConfirmacion", Namespace = "")]

the return value is serialized as
<RespuestaOConfirmacion>
<Respuesta ...>
...
</RespuestaOConfirmacion>

That is, the Respuesta or the ConfrimacionPeticion are wrapped with
<RespuestaOConfirmacion> which again is not what I want.
So summarizing, how do you express either in C# or in WSDL that you can
return any of two different elements under <soap:Body>?

Thanks in advance.
--
David Mediavilla

Jan 23 '06 #2
Yunus Emre ALP÷ZEN [MVP] wrote:
My advice u to use a union for multiple return types...
I appreciate your answer. From my understanding and the message from
the WSDL editor in Visual Studio, union only works with simpleType.
Respuesta and ConfirmacionPeticion are complexType.

I am going to look into abstract types, but I understand that it
requires including an xsi:type in <Respuesta ...> and
<ConfirmacionPeticion ...>
Yunus Emre ALP÷ZEN

<6k*******@sneakemail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I am trying to return one of two different objects from the same
method, but I can not do it in WSDL or C#.

I have a web service with three methods.

I have been told that one of the methods must return either <Respuesta
...> or <ConfirmacionPeticion ...> directly under the SOAP Body. Other
methods are already capable of returning just <Respuesta ...> or just
<ConfirmacionPeticion ...>. What is new is one method being capable of
returning both types. So summarizing, how do you express either in C# or in WSDL that you can
return any of two different elements under <soap:Body>?

Thanks in advance.
--
David Mediavilla


--
David Mediavilla

Jan 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: Mike Meng | last post by:
hi all, I'm a newbie Python programmer with a C++ brain inside. I have a lightweight framework in which I design a base class and expect user to extend. In other part of the framework, I heavily...
2
by: Aryeh M. Friedman | last post by:
If I have something like this: class NumberException { }; class Number { public: ... virtual unsigned long getValue() {throw(NumberException);}; ...
20
by: verec | last post by:
One problem I've come accross in designing a specific version of auto_ptr is that I have to disntiguish between "polymorphic" arguments and "plain" ones, because the template has to, internally,...
7
by: Mr. Ed | last post by:
I have a base class which has about 150 derived classes. Most of the derived classes are very similar, and many don't change the base class at all. All the derived classes have a unique factory...
7
by: James Fortune | last post by:
In response to different users or situations (data context) I transform the appearance and characteristics of Access Forms through code. This seems to fit in with the idea of polymorphism. Do...
5
by: Ben Pope | last post by:
Hi all, This is not something I've played around with much, but I'm designing some factories and I want a function like this: template<class T> T* Creator() { return new T; }
3
by: jacek.dziedzic | last post by:
Hello! Suppose I have a class base, with virtual methods and a virtual destructor and a bunch of classes, derived1, derived2, ... which publicly derive from base. I then have a pointer base*...
8
by: Angelwings | last post by:
Hi everyone, I've to write my own definition of a BST with polymorphic data, as an university course project. I have troubles about comparing data when it's defined as polymorphic pointer. In my...
0
by: Bob Hoeppner | last post by:
I think an overloading of the Indexer and the Add methods is quirky, but can be justifiable, especially if all coders involved understand the possible downsides. The plus side is that there may be...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.