473,581 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem generating client proxy with complex return types

Dear all,
I am having trouble generating a client proxy for a webservice whose
methods return a "complex" type. The type is complex in that it is a
class whose members are a mix of primitive types and of more elaborate
classes implementing IXmlSerializabl e. The resulting WSDL file for the
webservice has two separate schemas in its <types> sections, and the
client proxy (generated with wsdl.exe) is missing the definitions of
the IXmlSerializabl e types. More details follow.

I could reproduce the problem with a simple example. The webservice is
called WSTest.Service1 @ http://localhost/WSTest/Service1.asmx, and it
has a method called HelloWorld.
Here is the Service1.asmx file (hope the formatting won't go wild):
------------------------------------------------
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Diagnost ics;
using System.Web;
using System.Web.Serv ices;
using System.Xml;
using System.Xml.Seri alization;
using System.Xml.Sche ma;

namespace WSTest
{
// This is the IXmlSerializabl e derivative, member of the webmethod's
actual return type
public class WSTestDetail: IXmlSerializabl e
{
// Class data
public string Code;
public string Description;

// IXmlSerializabl e implementation
public void WriteXml (XmlWriter writer)
{
// ...
}

public void ReadXml (XmlReader reader)
{
// ...
}

public XmlSchema GetSchema ()
{
XmlSchemaSequen ce seq = new XmlSchemaSequen ce ();
XmlSchemaElemen t element;

element = new XmlSchemaElemen t ();
element.Name = "Code";
element.SchemaT ypeName = new XmlQualifiedNam e ("string",
"http://www.w3.org/2001/XMLSchema");
element.MinOccu rs = 0;
element.MaxOccu rs = 1;
seq.Items.Add (element);

element = new XmlSchemaElemen t ();
element.Name = "Descriptio n";
element.SchemaT ypeName = new XmlQualifiedNam e ("string",
"http://www.w3.org/2001/XMLSchema");
element.MinOccu rs = 0;
element.MaxOccu rs = 1;
seq.Items.Add (element);

XmlSchemaComple xType type = new XmlSchemaComple xType ();
type.Particle = seq;
type.Name = "WSTestDetailTy pe";

XmlSchemaElemen t root = new XmlSchemaElemen t ();
root.Name = "WSTestDeta il";
root.SchemaType Name = new XmlQualifiedNam e ("WSTestDetailT ype",
"http://www.testme.org/types");

XmlSchema schema = new XmlSchema ();
schema.Id = "WSTestDetailSc hema";
schema.TargetNa mespace = "http://www.testme.org/types";

schema.Namespac es.Add ("xs", "http://www.w3.org/2001/XMLSchema");

schema.Items.Ad d (type);
schema.Items.Ad d (root);

return schema;
}
}

// This is the return type of the webmethod
public class WSTestResult
{
public WSTestDetail Detail;
public string Status;
}

/// <summary>
/// Summary description for Service1.
/// </summary>
[WebService(Name space="http://www.testme.org/ws")]
public class Service1 : System.Web.Serv ices.WebService
{
public Service1()
{
InitializeCompo nent();
}

#region Component Designer generated code
// ...
#endregion

[WebMethod]
public WSTestResult HelloWorld()
{
return new WSTestResult ();
}
}
}
------------------------------------------------

The WSDL document (Service1.wsdl) :
------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitio ns xmlns:s1="http://www.testme.org/types"
xmlns:http="htt p://schemas.xmlsoap .org/wsdl/http/"
xmlns:soap="htt p://schemas.xmlsoap .org/wsdl/soap/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soapenc=" http://schemas.xmlsoap .org/soap/encoding/"
xmlns:tns="http ://www.testme.org/ws"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:mime="htt p://schemas.xmlsoap .org/wsdl/mime/"
targetNamespace ="http://www.testme.org/ws"
xmlns:wsdl="htt p://schemas.xmlsoap .org/wsdl/">
<wsdl:types>
<s:schema elementFormDefa ult="qualified"
targetNamespace ="http://www.testme.org/ws">
<s:import namespace="http ://www.testme.org/types" />
<s:element name="HelloWorl d">
<s:complexTyp e />
</s:element>
<s:element name="HelloWorl dResponse">
<s:complexTyp e>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1"
name="HelloWorl dResult" type="tns:WSTes tResult" />
</s:sequence>
</s:complexType>
</s:element>
<s:complexTyp e name="WSTestRes ult">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Detail">
<s:complexTyp e>
<s:sequence>
<s:any namespace="http ://www.testme.org/types" />
</s:sequence>
</s:complexType>
</s:element>
<s:element minOccurs="0" maxOccurs="1" name="Status"
type="s:string" />
</s:sequence>
</s:complexType>
</s:schema>
<s:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace ="http://www.testme.org/types" id="WSTestDetai lSchema">
<xs:complexTy pe name="WSTestDet ailType">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="Code"
type="xs:string " />
<xs:element minOccurs="0" maxOccurs="1" name="Descripti on"
type="xs:string " />
</xs:sequence>
</xs:complexType>
<xs:element name="WSTestDet ail" type="s1:WSTest DetailType" />
</s:schema>
</wsdl:types>
<wsdl:message name="HelloWorl dSoapIn">
<wsdl:part name="parameter s" element="tns:He lloWorld" />
</wsdl:message>
<wsdl:message name="HelloWorl dSoapOut">
<wsdl:part name="parameter s" element="tns:He lloWorldRespons e" />
</wsdl:message>
<wsdl:portTyp e name="Service1S oap">
<wsdl:operati on name="HelloWorl d">
<wsdl:input message="tns:He lloWorldSoapIn" />
<wsdl:output message="tns:He lloWorldSoapOut " />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="Service1S oap" type="tns:Servi ce1Soap">
<soap:binding transport="http ://schemas.xmlsoap .org/soap/http"
style="document " />
<wsdl:operati on name="HelloWorl d">
<soap:operati on soapAction="htt p://www.testme.org/ws/HelloWorld"
style="document " />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Service1" >
<documentatio n xmlns="http://schemas.xmlsoap .org/wsdl/" />
<wsdl:port name="Service1S oap" binding="tns:Se rvice1Soap">
<soap:address location="http://localhost/WSTest/Service1.asmx" />
</wsdl:port>
</wsdl:service>
</wsdl:definition s>
------------------------------------------------

As you can see, with WSTestDetail providing its own GetSchema()
implementation, we have 2 <schema>'s in the WSDL.
WSTestResult.De tail has a strange declaration: instead of the expected
<s:element name="Detail" type="s1:WSTest DetailType">, I get a
complexType/sequence/any specification. Why not; the 2nd schema has
only one toplevel element so I guess that's fine and leads to no
ambiguities.
Now the client proxy (wsdl.exe Service1.wsdl):
------------------------------------------------
using System.Diagnost ics;
using System.Xml.Seri alization;
using System;
using System.Web.Serv ices.Protocols;
using System.Componen tModel;
using System.Web.Serv ices;
/// <remarks/>
[System.Diagnost ics.DebuggerSte pThroughAttribu te()]
[System.Componen tModel.Designer CategoryAttribu te("code")]
[System.Web.Serv ices.WebService BindingAttribut e(Name="Service 1Soap",
Namespace="http ://www.testme.org/ws")]
public class Service1 :
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol {

/// <remarks/>
public Service1() {
this.Url = "http://localhost/WSTest/Service1.asmx";
}

/// <remarks/>

[System.Web.Serv ices.Protocols. SoapDocumentMet hodAttribute("h ttp://www.testme.org/ws/HelloWorld",
RequestNamespac e="http://www.testme.org/ws",
ResponseNamespa ce="http://www.testme.org/ws",
Use=System.Web. Services.Descri ption.SoapBindi ngUse.Literal,
ParameterStyle= System.Web.Serv ices.Protocols. SoapParameterSt yle.Wrapped)]
public WSTestResult HelloWorld() {
object[] results = this.Invoke("He lloWorld", new object[0]);
return ((WSTestResult) (results[0]));
}

/// <remarks/>
public System.IAsyncRe sult BeginHelloWorld (System.AsyncCa llback
callback, object asyncState) {
return this.BeginInvok e("HelloWorld ", new object[0], callback,
asyncState);
}

/// <remarks/>
public WSTestResult EndHelloWorld(S ystem.IAsyncRes ult asyncResult)
{
object[] results = this.EndInvoke( asyncResult);
return ((WSTestResult) (results[0]));
}
}

/// <remarks/>
[System.Xml.Seri alization.XmlTy peAttribute(Nam espace="http://www.testme.org/ws")]
public class WSTestResult {

/// <remarks/>
public WSTestDetailSch ema Detail;

/// <remarks/>
public string Status;
}
------------------------------------------------

WSTestResult.De tail's type is named WSTestDetailSch ema (I would have
expected WSTestDetailTyp e), but again, why not. The missing type
declaration for WSTestDetailSch ema is much more annoying as this makes
the WSDL useless for clients.

Is there any reason why this is happening? Why do I have 2 schemas in
my WSDL? How can I ask that WSTestResult.De tail be of type
s1:WSTestDetail Type in the WSDL? Since the class in Service1.asmx
implements IXmlSerializabl e, I cannot use Xml serialization attributes
like XmlType. The interface is needed because we want to have fine
control on the serialization.
I hope the question is not too stupid. The thing is, I'm not too
familiar with schemas, namespaces and such. Also, we're in 1.1 and
IXmlSerializabl e is not very well documented.

Thanks in advance!

Best regards,
Thomas

Feb 22 '06 #1
1 2850
Seems that wsdl.exe does not like IXmlSerializabl e. I could get around
this by intercepting the "?wsdl" call in Application_Beg inRequest (),
getting the incorrect ServiceDescript ion from there (with
ServiceDescript ionReflector), and altering
ServiceDescript ion.Types.Schem as.
The idea is to collapse all schemas therein into the first one, replace
the complexType/sequence/any with a type="..." attribute, and fix up
all namespaces references.

Not very elegant but it works very well... Also, the default
documentation/test page for the service is not affected, as would have
been the case if I had added a <wsdlHelpGenera tor> tag in Web.config.

Thomas

Feb 24 '06 #2

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

Similar topics

2
10985
by: raymond | last post by:
Hi, Is it possible to create a proxy client class or a web service method by VS.NET without using wsdl? My stupid client is using a xml schema (.xsd) to describe all their web service methods (and my webmethods) by Java (Apache toolkit) instead of using WSDL. What should I do? Thanks a lot! Raymond
4
1687
by: Flare | last post by:
OK. I'll try explain my problem so simple as possible. I have to send a complex data type to a WebService from a Asp.net webapplication. My Data type look like this. (A class with a porperty) ------------- namespace Elsam.Turabs.ClassLibraries.TurabsLogExeption{
3
2339
by: Ohad Young | last post by:
Hi, I have a webservice method that returns an instance of a custom class I created (e.g., bank account). The class definition in the webservice contains properties, overrides Object.ToString method and etc. However, the proxy created for the webservice contains a definition for this class without the code I wrote. Instead it contains...
2
2744
by: yqlu | last post by:
I hava developed a client in C# that is connected to a 3-party XML Web Services developed in Java based on the AXIS 1.1. Most methods call are successful except for one method named "findObjects" and return a complex type "FieldSearchResult". The error message as following : "Cannot assign object of type System.String to an object of type...
7
2913
by: Nalaka | last post by:
Hi, I created a sinple web service that returns a dataSet. Then I created a client program that uses this web service (that returns the Dataset). My question is, how did the client figure out to create a "DataSet" as the return type from the webservice?
1
5538
by: J. Askey | last post by:
I am implementing a web service and thought it may be a good idea to return a more complex class (which I have called 'ServiceResponse') in order to wrap the original return value along with two other properties... bool error; string lastError; My whole class looks like this... using System;
3
1368
by: kkao77 | last post by:
I am trying to use schema to validate the data that user sent to my service. How do I achieve that using schema? Do I give schema to the client? or do I write my own schema validation inside web service? How does it work? Thank you.
13
2153
by: John Kotuby | last post by:
I am expecting the answer to be, "of course not" or " are you kidding?", but maybe (hopefully) I am wrong and somebody can point me to an ingenious example of how the impossible just takes a little more work. TIA
0
2512
by: RobR2009 | last post by:
I am having trouble with a C# proxy page I am writing which allows me to do cross domain AJAX calls with Javascript. The problem is with certain pages that contain pound signs £ that are not HTML encoded in the source that I am trying to extract with the WebRequest and WebResponse objects. The page is using a charset of iso-8859-1 which I think...
0
7804
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...
0
8156
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8180
tracyyun
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...
0
5366
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...
0
3809
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...
0
3832
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2307
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
1
1409
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1144
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.