473,320 Members | 1,580 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,320 software developers and data experts.

Passing XmlDocument-derived class in a WebMethod

Hello,

I have designed a WebService with the following method :

[WebMethod]
public DbAppAnswer GetDs(DbAppRequest request)
DbAppRequest and DbAppAnswer are defined as :

public class DbAppRequest : DbAppMessageBase
public class DbAppAnswer : DbAppMessageBase
public abstract class DbAppMessageBase : XmlDocument
Now up on the call to WebMethod GetDs, I have the following exception :

---------------------------------------------------8<-------------------------------------------------------------------------
System.Web.Services.Protocols.SoapException: Server was unable to read
request. ---System.InvalidOperationException: There is an error in
XML document (1, 370). ---System.InvalidCastException: Unable to cast
object of type 'System.Xml.XmlElement' to type
'DbAppFrameworkMessages.DbAppRequest'.\n at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationReader1.Read1_GetDs()\n
at
Microsoft.Xml.Serialization.GeneratedAssembly.Arra yOfObjectSerializer.Deserialize(XmlSerializationRe ader
reader)\n at
System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader xmlReader,
String encodingStyle, XmlDeserializationEvents events)\n --- End of
inner exception stack trace ---\n at
System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader xmlReader,
String encodingStyle, XmlDeserializationEvents events)\n at
System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader xmlReader,
String encodingStyle)\n at
System.Web.Services.Protocols.SoapServerProtocol.R eadParameters()\n
--- End of inner exception stack trace ---\n at
System.Web.Services.Protocols.SoapServerProtocol.R eadParameters()\n
at System.Web.Services.Protocols.WebServiceHandler.Co reProcessRequest()
---------------------------------------------------8<-------------------------------------------------------------------------
Another thing I noticed is that the generated proxy has this signature
:

public System.Xml.XmlNode GetDs(System.Xml.XmlNode request)

Well I understand that there's a problem on the server-side : the
request is sent as an XmlElement and
there's an exception casting an XmlElement to DbAppRequest.
What guidance could you give me ?
Should I write a "cast-operator" in DbAppRequest so as to automatically
cast XmlElement to DbAppRequest ?
Also, what best practices could you give me so as to optimize the body
of the SOAP message since DbAppRequest is already XML.

Thanks a lot for your answers,
Olivier.

Jul 13 '06 #1
1 1792
Solved the problem by declaring :

public abstract class DbAppMessageBase : XmlDocument,IXmlSerializable
Here is the implementation of IXmlSerializable :
public System.Xml.Schema.XmlSchema GetSchema()
{
return null;
}

public void ReadXml(XmlReader reader)
{
InnerXml=reader.ReadString();
}

public void WriteXml(XmlWriter writer)
{
writer.WriteString(InnerXml);
}
I had also to edit manually the WSDL-generated proxy because it
generated methods with DataSet parameters :-(.
Replacing with the proper types (DbAppAnswer and DbAppRequest) worked.

Well it seems that WSDL has trouble generating methods from WebMethods
taking parameters declared as user-classes...
Can somebody at MS confirm ??

Jul 14 '06 #2

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

Similar topics

3
by: Hans [DiaGraphIT] | last post by:
Hi! Can anyone help me with translating a VB-code to C#? I'm reading the walkthrough: Passing data to a custom action. In part 4 were you create an installer class there is a example of...
1
by: Dugr | last post by:
I'm writing a simple .NET 2.0 application and I'm writing a DLL for this app. I want to pass an XML document into a public function of the dll and read it's nodes and then pass the document around...
4
by: saish | last post by:
Hello Need your help, I have a C++ win32 dll which takes xml document type by reference. I need to call this dll from c# .net. I tried using DllImport, but dll funtion when call does not...
0
by: BobbyS | last post by:
I've a xml file.I'm taking its data passing it to a method in string form and converting that string "xmlData" to a array of bytes by Convert.FromBase64String(xmlData) but I'm getting a exception...
0
by: tkarthi06 | last post by:
Hi, Can any one please tell how to pass Web Services Credentials(Web Services Username and Password) using WCF. Inorder to Communicate with Web Services i have to provide username and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.