473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Web Service returning xs:choice as return type in C++ .NET

Hi,

I want to consume a Web Service that returns a choice, but my C++ client
always receives the same returned type. On the other hand, when I am using a
Java client, it is working fine (of course, the generated proxy is not the
same).

When I am looking at the C++ generated code, it seems fine, but when I am
executing the code, I always get the first choice type.

Do someone already used a returned choice in C++ ?

(I am using Visual Studio 2003).
Here is the execute code:

// -------------------------
// My test code
// -------------------------
Object *queryResult = webService->queryMatchingPersonsByTraits(
fillRequestType(condition), szProductID, Convert::ToString(iMaxReturnRow),
totalNumberOfMatches, timestamp );

Query::PersonQueryResponseTypeMatchingProfiles *profiles =
dynamic_cast<Query:: PersonQueryResponseTypeMatchingProfiles *>(queryResult);
if ( profiles == NULL )
{
Query::PersonQueryResponseTypeError* error =
dynamic_cast<Query::PersonQueryResponseTypeError*> (queryResult);
String *value = error->Value;
}

//I never receive a PersonQueryResponseTypeMatchingProfiles in my C++ code,
but I am receiving some in the Java code.
//---------------------------
// Generated Proxy method declaration
//---------------------------
public:
[System::Web::Services::Protocols::SoapDocumentMeth odAttribute(S"http://www.openuri.org/queryMatchingPersonsByTraits",
RequestElementName=S"PersonQueryRequest",
RequestNamespace=S"http://.../personqueryrequest",
ResponseElementName=S"PersonQueryResponse",
ResponseNamespace=S"http://.../personquery",
Use=System::Web::Services::Description::SoapBindin gUse::Literal,
ParameterStyle=System::Web::Services::Protocols::S oapParameterStyle::Wrapped)]
[returnvalue: System::Xml::Serialization::XmlElementAttribute(S" Error",
__typeof(Query::PersonQueryResponseTypeError))]
[returnvalue:
System::Xml::Serialization::XmlElementAttribute(S" MatchingProfiles",
__typeof(Query::PersonQueryResponseTypeMatchingPro files))]
System::Object *
queryMatchingPersonsByTraits(Query::PersonQueryReq uestTypeProfileData *
ProfileData, [System::Xml::Serialization::XmlAttributeAttribute]
System::String * SystemID,
[System::Xml::Serialization::XmlAttributeAttribute( DataType=S"integer")]
System::String * MaxNumMatches,
[System::Xml::Serialization::XmlAttributeAttribute( DataType=S"integer")]
System::String * & TotalNumberOfMatches,
[System::Xml::Serialization::XmlAttributeAttribute] System::DateTime&
Timestamp);

//---------------------------
// Generated Proxy method definition
//---------------------------
inline System::Object *
Person::queryMatchingPersonsByTraits(Query::Person QueryRequestTypeProfileData
* ProfileData, [System::Xml::Serialization::XmlAttributeAttribute]
System::String * SystemID,
[System::Xml::Serialization::XmlAttributeAttribute( DataType=S"integer")]
System::String * MaxNumMatches,
[System::Xml::Serialization::XmlAttributeAttribute( DataType=S"integer")]
System::String * & TotalNumberOfMatches,
[System::Xml::Serialization::XmlAttributeAttribute] System::DateTime&
Timestamp) {
System::Object* __mcTemp__1[] = new System::Object*[3];
__mcTemp__1[0] = ProfileData;
__mcTemp__1[1] = SystemID;
__mcTemp__1[2] = MaxNumMatches;
System::Object * results[] =
this->Invoke(S"queryMatchingPersonsByTraits", __mcTemp__1);
TotalNumberOfMatches = (__try_cast<System::String * >(results[1]));
Timestamp = (*__try_cast<__box System::DateTime * >(results[2]));
return (__try_cast<System::Object * >(results[0]));
};
// -------------------------------
// XML part
// -------------------------------

<xs:element name="QueryResponse" type="pq:QueryResponseType">
</xs:element>
<xs:complexType name="QueryResponseType">
<xs:choice>
<xs:element name="Error">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="type" type="pq:ErrorType" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="Profiles">
<xs:complexType>

</xs:complexType>
</xs:element>
</xs:choice>

</xs:complexType>
<xs:simpleType name="ErrorType">
<xs:restriction base="xs:string">
<xs:enumeration value="client"/>
<xs:enumeration value="server"/>
</xs:restriction>
</xs:simpleType>


Nov 22 '05 #1
3 3433
Hi dgaucher,
I want to consume a Web Service that returns a choice, but my C++ client
always receives the same returned type.


What's the return "xs:choice" here, a custom type you defined in your
webservice application, something like a enum type?

By the way, do you have tried to use other .NET language code(e.g. C#) to
consume the Web Service, is it OK?
Thanks for your understanding!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

Nov 22 '05 #2
Hy Gary
By the way, do you have tried to use other .NET language code(e.g. C#) to
consume the Web Service, is it OK?
I have just tried with C# and I am having the same result as in C++. If you
look at the schema, you will find that I should receive an “Error” or a
“MatchingProfiles”. What I am getting from either C# or C++ is always the
“Error”. When the Web Service effectlively returned an “Error”, it is filled
properly, but when it returns a “MatchingProfiles”, I am getting an “Error”
with the default data in.
What's the return "xs:choice" here, a custom type you defined in your
webservice application, something like a enum type?


Effectively, the return is a complex type.
//--------------------------------------------------------------------------
<xs:complexType name="PersonQueryResponseType">
<xs:choice>
<xs:sequence>
<xs:element name="Error">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="type" type="pq:ErrorType" use="required"/>

</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="MatchingProfiles">
<xs:complexType>
<xs:sequence>
<xs:element name="UnknownMatchingPerson" minOccurs="0"
maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Alias" minOccurs="0" maxOccurs="10">

<xs:complexType>
<xs:attribute name="FirstName" type="xs:string"
use="optional"/>
<xs:attribute name="LastName" type="xs:string"
use="optional"/>
<xs:attribute name="MiddleName" type="xs:string"
use="optional"/>
<xs:attribute name="NameSuffix" type="xs:string"
use="optional"/>
<xs:attribute name="AliasDOB" type="xs:date"
use="optional"/>
<xs:attribute name="AliasSSN" type="xs:string"
use="optional"/>
</xs:complexType>
</xs:element>
<xs:element name="ScarsMarksTattoos" minOccurs="0"
maxOccurs="10">
<xs:complexType>
<xs:attribute name="SMTNCICCode" type="xs:string"
use="optional"/>
<xs:attribute name="SMTDescription" type="xs:string"
use="optional"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="ConfidenceLevel" type="xs:double"
use="required"/>
<xs:attribute name="MPI" type="xs:string" use="required"/>

<xs:attribute name="MNI" type="xs:string" use="required"/>

<xs:attribute name="FirstName" type="xs:string"
use="optional"/>
<xs:attribute name="LastName" type="xs:string"
use="optional"/>
<xs:attribute name="MiddleName" type="xs:string"
use="optional"/>
<xs:attribute name="NameSuffix" type="xs:string"
use="optional"/>
<xs:attribute name="SSN" type="xs:string" use="optional"/>

<xs:attribute name="StateID" type="xs:string" use="optional"/>

<xs:attribute name="DateOfBirth" type="xs:date"
use="optional"/>
<xs:attribute name="CityOfBirth" type="xs:string"
use="optional"/>
<xs:attribute name="CountyOfBirth" type="xs:string"
use="optional"/>
<xs:attribute name="StateOfBirth" type="xs:string"
use="optional"/>
<xs:attribute name="CountryOfBirth" type="xs:string"
use="optional"/>
<xs:attribute name="Gender" type="xs:string" use="optional"/>

<xs:attribute name="Race" type="xs:string" use="optional"/>

<xs:attribute name="RightEyeColor" type="xs:string"
use="optional"/>
<xs:attribute name="LeftEyeColor" type="xs:string"
use="optional"/>
<xs:attribute name="OperatorLicenseNumber" type="xs:string"
use="optional"/>
<xs:attribute name="OperatorLicenseState" type="xs:string"
use="optional"/>
</xs:complexType>
</xs:element>
<xs:element name="KnownMatchingPerson" minOccurs="0"
maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="ConfidenceLevel" type="xs:double"
use="required"/>
<xs:attribute name="MPI" type="xs:string" use="required"/>

</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
<xs:attribute name="TotalNumberOfMatches" type="xs:integer"
use="required"/>
<xs:attribute name="Timestamp" type="xs:dateTime" use="required"/>

</xs:complexType>

//--------------------------------------------------------------------------
// where ErrorType is
<xs:simpleType name="ErrorType">
<xs:restriction base="xs:string">
<xs:enumeration value="client"/>
<xs:enumeration value="server"/>
</xs:restriction>
</xs:simpleType>

Thanks for your help
Dominique Gaucher
Nov 22 '05 #3
Hi Dominique,

Thanks for your response, as for the .NET wsdl generated proxy class's
return type problem you mentioned, I've done some research on the .NET's
WSDL parser (wsdl.exe) and found that the problem on parsing the
xsd:choice element does be an existing limitation of the .net 's wsdl.exe
tool.

In fact, the xsd:choice type should be mapped to a variant type which can
reference a certain type among a given type groups. However, currently the
..net's wsdl.exe tool dosn't support the correct mapping on such element(
Variant Type). That's why we'll always get the fixed Type object when
consuming a webservivce with a custom WSDL which contains xsd:choice
element as return type.

Currently, the available workaround is to consuming the xmlwebservice
direct via the HttpWebRequest class in the System.Net namespace. The
wsdl.exe generated proxy class is also using the HttpWebRequest to send the
underlying SOAP message internally. So we can create our own custom proxy
class which directly use the HttpWebRequest to send the SOAP xml message
and get the returned XML SOAP message and then parsing the certain object
instance to the correct type (manually use the xmlSerialier).

If there is any further questions, please feel free to post here.
Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 22 '05 #4

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

Similar topics

3
by: dgaucher | last post by:
Hi, I want to consume a Web Service that returns a choice, but my C++ client always receives the same returned type. On the other hand, when I am using a Java client, it is working fine (of...
1
by: Oleg Ogurok | last post by:
Hi all, I have a complex type defined as follows: <xs:complexType name="SchedulingMethodType"> <xs:choice maxOccurs="1"> <xs:element name="Interval" type="xs:duration" /> <xs:element...
4
by: Sergey Poberezovskiy | last post by:
Hi, As part of my schema I need to ensure that at least one of two fields have values. I defined my schema as follows: .... <xs:choice> <xs:element ref="el1"/> <xs:element ref="el2"/>...
2
by: Sergey Poberezovskiy | last post by:
Hi, If I define my schema as <xs:choice> <xs:sequence> <xs:element ref="el_1" /> <xs:element ref="el_2" /> </xs:sequence> <xs:sequence>
2
by: pawel.pabich | last post by:
Hajo, I know only one way of forcing element to have one or more childes: <xs:element name="saleOrSupplyMethod"> <BR/> <xs:complexType> <xs:choice> <xs:sequence> <xs:element...
7
by: rbarschaw | last post by:
I have the following schema designed: <xs:complexType name="AzzFeature-BoxType" mixed="true"> <xs:choice minOccurs="1" maxOccurs="unbounded"> <xs:element ref="Sub-Head" minOccurs="1"...
2
by: hooomee | last post by:
Given: <xs:choice maxOccurs=5> <xs:element name="Foo" type="bar" /> <xs:element name="Foo1" type="bar" /> <xs:element name="Foo2" type="bar" /> </xs:choice> Is the choice made once and then...
2
by: cmay | last post by:
I am beginning to wonder if it is not possible to get this working. I am trying to do: <root> <a/> <b/> <c/> </root>
0
by: =?Utf-8?B?RGFtaWFu?= | last post by:
(This is using .net version 2.0.50727 and system.xml 2.0.50727.42) I am getting an error when serializing using classes generated by xsd.exe. The error is of the type "The Type <typewas not...
0
by: Peter Larsen | last post by:
Is this really a valid schema design? <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="root">...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.