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 <ConfirmacionPe ticion ...> directly under the SOAP Body. Other
methods are already capable of returning just <Respuesta ...> or just
<ConfirmacionPe ticion ...>. What is new is one method being capable of
returning both types.
I have been modifying over one of the previous methods:
[WebMethodAttrib ute( Description = "Blah...")]
[SoapDocumentMet hod( ourMethodNamesp ace, Use = SoapBindingUse. Literal,
ParameterStyle = SoapParameterSt yle.Bare)]
[return: XmlElement( Respuesta.Marca , Namespace =
Respuesta.Espac ioNombres)]
public Respuesta solicitaRespues taAsincrona( ...)
The obvious thing is to substitute the return type by object:
[WebMethodAttrib ute( Description = "Blah...")]
[SoapDocumentMet hod( ourMethodNamesp ace, Use = SoapBindingUse. Literal,
ParameterStyle = SoapParameterSt yle.Bare)]
public object solicitaRespues taAsincrona( ...)
But then the automatic WSDL becomes:
<wsdl:message name="solicitaR espuestaAsincro naSoapOut">
<wsdl:part name="solicitaR espuestaAsincro naResult"
element="tns:so licitaRespuesta AsincronaResult "/>
</wsdl:message>
That is, under <soap:Body> I get a <solicitaRespue staAsincronaRes ult>
element followed by the members of the actual object being returned.
This is not what I want, I want either <Respuesta> or
<ConfirmacionRe spuesta>.
I then tried to have several XML return attributes:
[WebMethodAttrib ute( Description = "Blah...")]
[SoapDocumentMet hod( ourMethodNamesp ace, Use = SoapBindingUse. Literal,
ParameterStyle = SoapParameterSt yle.Bare)
[return:
XmlElement( Respuesta.Marca ,
Namespace = Respuesta.Espac ioNombres),
XmlElement( ConfirmacionPet icion.Marca,
Namespace = ConfirmacionPet icion.EspacioNo mbres)]]
public object solicitaRespues taAsincrona( ...)
but then I get:
System.InvalidO perationExcepti on: You need to add
XmlChoiceIdenti fierAttribute to the 'solicitaRespue staAsincronaRes ult'
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 elementFormDefa ult="qualified" >
<s:complexTyp e name="Respuesta OConfirmacion" >
<s:sequence>
<s:choice minOccurs="0" maxOccurs="1">
<s:element minOccurs="1" maxOccurs="1" name="Respuesta " />
<s:element minOccurs="1" maxOccurs="1"
name="Confirmac ionPeticion" />
</s:choice>
</s:sequence>
</s:complexType>
<!-- Without an explicit element:
// CODEGEN: The operation binding 'solicitaRespue staAsincrona'
from
namespace 'http://www.map.es/scsp/' was ignored.
Specifying a type for use=literal messages is not supported.
Type name='Respuesta OConfirmacion' from targetNamespace =''
cannot be used as top-level any element.-->
<s:element name="Respuesta OConfirmacion"
type="Respuesta OConfirmacion"/>
</s:schema>
</wsdl:types>
and
<wsdl:message name="solicitaR espuestaAsincro naSoapOut">
<wsdl:part name="solicitaR espuestaAsincro naResult"
element="Respue staOConfirmacio n"/>
</wsdl:message>
This type is stubbed as
public partial class RespuestaOConfi rmacion
{
[XmlElement("Con firmacionPetici on", typeof(Confirma cionPeticion))]
[XmlElement("Res puesta", typeof(Respuest a))]
[XmlChoiceIdenti fier("nombreEle mento")]
public object unaRespuestaOUn aConfirmacion;
[System.Xml.Seri alization.XmlIg noreAttribute()]
public RespuestaOConfi rmacionEleccion nombreElemento;
}
[System.Xml.Seri alization.XmlTy peAttribute(Inc ludeInSchema =
false)]
public enum
RespuestaOConfi rmacionEleccion
{
ConfirmacionPet icion,
Respuesta
}
I then tried with:
....
[return:
XmlChoiceIdenti fier(MemberName = "nombreElemento "),
XmlElement( Respuesta.Marca ,
Namespace = Respuesta.Espac ioNombres),
XmlElement( ConfirmacionPet icion.Marca,
Namespace = ConfirmacionPet icion.EspacioNo mbres)]
public RespuestaOConfi rmacion solicitaRespues taAsincrona( ...)
This causes:
System.InvalidO perationExcepti on: There was an error reflecting
'solicitaRespue staAsincronaRes ult'. --->
System.InvalidO perationExcepti on: Missing 'nombreElemento ' member
needed for serialization of choice 'solicitaRespue staAsincronaRes ult'.
in spite of me assigning a value to the nombreElemento field in the
return value.
If I have
[return:
XmlChoiceIdenti fier(MemberName = "nombreElemento "),
XmlElement( Respuesta.Marca ,
Namespace = Respuesta.Espac ioNombres),
XmlElement( ConfirmacionPet icion.Marca,
Namespace = ConfirmacionPet icion.EspacioNo mbres)]
[return: XmlElement("Res puestaOConfirma cion", Namespace = "")]
the return value is serialized as
<RespuestaOConf irmacion>
<Respuesta ...>
....
</RespuestaOConfi rmacion>
That is, the Respuesta or the ConfrimacionPet icion are wrapped with
<RespuestaOConf irmacion> 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 2 5554
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*******@snea kemail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.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 <ConfirmacionPe ticion ...> directly under the SOAP Body. Other methods are already capable of returning just <Respuesta ...> or just <ConfirmacionPe ticion ...>. What is new is one method being capable of returning both types.
I have been modifying over one of the previous methods:
[WebMethodAttrib ute( Description = "Blah...")] [SoapDocumentMet hod( ourMethodNamesp ace, Use = SoapBindingUse. Literal, ParameterStyle = SoapParameterSt yle.Bare)] [return: XmlElement( Respuesta.Marca , Namespace = Respuesta.Espac ioNombres)] public Respuesta solicitaRespues taAsincrona( ...)
The obvious thing is to substitute the return type by object:
[WebMethodAttrib ute( Description = "Blah...")] [SoapDocumentMet hod( ourMethodNamesp ace, Use = SoapBindingUse. Literal, ParameterStyle = SoapParameterSt yle.Bare)] public object solicitaRespues taAsincrona( ...)
But then the automatic WSDL becomes:
<wsdl:message name="solicitaR espuestaAsincro naSoapOut"> <wsdl:part name="solicitaR espuestaAsincro naResult" element="tns:so licitaRespuesta AsincronaResult "/> </wsdl:message>
That is, under <soap:Body> I get a <solicitaRespue staAsincronaRes ult> element followed by the members of the actual object being returned. This is not what I want, I want either <Respuesta> or <ConfirmacionRe spuesta>.
I then tried to have several XML return attributes:
[WebMethodAttrib ute( Description = "Blah...")] [SoapDocumentMet hod( ourMethodNamesp ace, Use = SoapBindingUse. Literal, ParameterStyle = SoapParameterSt yle.Bare) [return: XmlElement( Respuesta.Marca , Namespace = Respuesta.Espac ioNombres), XmlElement( ConfirmacionPet icion.Marca, Namespace = ConfirmacionPet icion.EspacioNo mbres)]] public object solicitaRespues taAsincrona( ...)
but then I get:
System.InvalidO perationExcepti on: You need to add XmlChoiceIdenti fierAttribute to the 'solicitaRespue staAsincronaRes ult' 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 elementFormDefa ult="qualified" > <s:complexTyp e name="Respuesta OConfirmacion" > <s:sequence> <s:choice minOccurs="0" maxOccurs="1"> <s:element minOccurs="1" maxOccurs="1" name="Respuesta " /> <s:element minOccurs="1" maxOccurs="1" name="Confirmac ionPeticion" /> </s:choice> </s:sequence> </s:complexType> <!-- Without an explicit element: // CODEGEN: The operation binding 'solicitaRespue staAsincrona' from namespace 'http://www.map.es/scsp/' was ignored. Specifying a type for use=literal messages is not supported. Type name='Respuesta OConfirmacion' from targetNamespace ='' cannot be used as top-level any element.--> <s:element name="Respuesta OConfirmacion" type="Respuesta OConfirmacion"/> </s:schema> </wsdl:types>
and
<wsdl:message name="solicitaR espuestaAsincro naSoapOut"> <wsdl:part name="solicitaR espuestaAsincro naResult" element="Respue staOConfirmacio n"/> </wsdl:message>
This type is stubbed as
public partial class RespuestaOConfi rmacion { [XmlElement("Con firmacionPetici on", typeof(Confirma cionPeticion))] [XmlElement("Res puesta", typeof(Respuest a))] [XmlChoiceIdenti fier("nombreEle mento")] public object unaRespuestaOUn aConfirmacion;
[System.Xml.Seri alization.XmlIg noreAttribute()] public RespuestaOConfi rmacionEleccion nombreElemento; }
[System.Xml.Seri alization.XmlTy peAttribute(Inc ludeInSchema = false)] public enum RespuestaOConfi rmacionEleccion { ConfirmacionPet icion, Respuesta }
I then tried with:
... [return: XmlChoiceIdenti fier(MemberName = "nombreElemento "), XmlElement( Respuesta.Marca , Namespace = Respuesta.Espac ioNombres), XmlElement( ConfirmacionPet icion.Marca, Namespace = ConfirmacionPet icion.EspacioNo mbres)] public RespuestaOConfi rmacion solicitaRespues taAsincrona( ...)
This causes:
System.InvalidO perationExcepti on: There was an error reflecting 'solicitaRespue staAsincronaRes ult'. ---> System.InvalidO perationExcepti on: Missing 'nombreElemento ' member needed for serialization of choice 'solicitaRespue staAsincronaRes ult'.
in spite of me assigning a value to the nombreElemento field in the return value.
If I have
[return: XmlChoiceIdenti fier(MemberName = "nombreElemento "), XmlElement( Respuesta.Marca , Namespace = Respuesta.Espac ioNombres), XmlElement( ConfirmacionPet icion.Marca, Namespace = ConfirmacionPet icion.EspacioNo mbres)] [return: XmlElement("Res puestaOConfirma cion", Namespace = "")]
the return value is serialized as <RespuestaOConf irmacion> <Respuesta ...> ... </RespuestaOConfi rmacion>
That is, the Respuesta or the ConfrimacionPet icion are wrapped with <RespuestaOConf irmacion> 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
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 ConfirmacionPet icion are complexType.
I am going to look into abstract types, but I understand that it
requires including an xsi:type in <Respuesta ...> and
<ConfirmacionPe ticion ...>
Yunus Emre ALPÖZEN
<6k*******@snea kemail.com> wrote in message news:11******** **************@ g14g2000cwa.goo glegroups.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 <ConfirmacionPe ticion ...> directly under the SOAP Body. Other methods are already capable of returning just <Respuesta ...> or just <ConfirmacionPe ticion ...>. 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 use the instance of
this base class (or its children class). How can I ensure the instance
IS-A base class instance, since Python is a fully dynamic typing
language?
I searched and found several different ways to do this:
|
by: Aryeh M. Friedman |
last post by:
If I have something like this:
class NumberException {
};
class Number {
public:
...
virtual unsigned long getValue() {throw(NumberException);};
...
|
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, cast to void *.
Specifically,
template <typename T> void f(T * t) {
void * p = dynamic_cast<void *>(t) ;
}
will not compile if T isn't of a class that has somewhere at least
|
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 method which
returns a new object of the derived type.
The problem I've got is that I now need to polymorphically clone a
derived class object, but I don't want to write a separate 'clone'
method for each of these 150 classes. Instead, I thought I...
|
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 people
consider Access Forms to be Polymorphic?
James A. Fortune
| |
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;
}
|
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* foo;
which a complicated code allocates as one of derived's and sets up.
|
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 situation I've something like:
class A {}
class B : public A {}
class C : public A {}
|
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 less code and
increased convenience for the person coding to the class. The downside
is that it is going to be harder for humans to understand, unless they
are familiar with it, and there may be a performance penalty depending
on the kind of...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |