471,082 Members | 812 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

WebMethod returning an XmlDocument generating a compile error in the client.

I have a WebMethod as follows:

[WebMethod]
public XmlDocument OrderContract(XmlDocument doc)
{
return OrderBLL.OrderContract(doc);
}

However, the client is generating a compile error when the following lines
are used:

OrderWS.ContractServices txn = new OrderWS.ContractServices ();
XmlDocument retxml = txn.OrderContractCert(xml);

However, this compiles clean:

OrderWS.ContractServices txn = new OrderWS.ContractServices ();
XmlNode retxml = txn.OrderContractCert(xml);

I have no idea why the client is expecting an XmlNode.
Jun 21 '06 #1
8 2741


Thirsty Traveler wrote:

However, the client is generating a compile error when the following lines
are used:

OrderWS.ContractServices txn = new OrderWS.ContractServices ();
XmlDocument retxml = txn.OrderContractCert(xml);

However, this compiles clean:

OrderWS.ContractServices txn = new OrderWS.ContractServices ();
XmlNode retxml = txn.OrderContractCert(xml);

I have no idea why the client is expecting an XmlNode.


Does it work if you cast the result? E.g.
XmlDocument retxml = txn.OrderContractCert(xml) as XmlDocument;
if (retxml != null) {
// now use retxml here
}

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 21 '06 #2
IIRC the cast won't work; it returns a node, not a document.

If you need a document reference, then create a new XmlDocument and
call ImportNode on it to clone that node into the new document.
Alternatively, see what OwnerDocument (on the XmlNode) says.

Marc

Jun 21 '06 #3
I am still unclear on why it is returning a node rather than a document when
the webmethod specifies XmlDocument as the return type.

"Marc Gravell" <ma**********@gmail.com> wrote in message
news:11**********************@c74g2000cwc.googlegr oups.com...
IIRC the cast won't work; it returns a node, not a document.

If you need a document reference, then create a new XmlDocument and
call ImportNode on it to clone that node into the new document.
Alternatively, see what OwnerDocument (on the XmlNode) says.

Marc

Jun 21 '06 #4


Marc Gravell wrote:
IIRC the cast won't work; it returns a node, not a document.
XmlNode is an astract class, somehow an instance of a derived class
needs to be returned, and XmlDocument is a derived class. But you are
right that the cast to XmlDocument does not work, a test here shows that
NodeType gives Element node so you could cast to XmlElement but not
XmlDocument.
Alternatively, see what OwnerDocument (on the XmlNode) says.


The OwnerDocument of the node returned is an XmlDocument instance but in
my test here (with .NET 1.1) does not even contain the node returned.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 21 '06 #5


Thirsty Traveler wrote:
I am still unclear on why it is returning a node rather than a document when
the webmethod specifies XmlDocument as the return type.


Web services communicate using SOAP and it seems any XmlNode sub type is
simply serialized in the SOAP message so it is kind of hard to decide on
the client side what concrete type the XmlNode had.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 21 '06 #6
Try this:
OrderWS.ContractServices txn = new OrderWS.ContractServices ();
XmlDocument retxml = (XmlDocument) txn.OrderContractCert(xml);

Does it work for you?

chanmm

"Thirsty Traveler" <nf*@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
I have a WebMethod as follows:

[WebMethod]
public XmlDocument OrderContract(XmlDocument doc)
{
return OrderBLL.OrderContract(doc);
}

However, the client is generating a compile error when the following lines
are used:

OrderWS.ContractServices txn = new OrderWS.ContractServices ();
XmlDocument retxml = txn.OrderContractCert(xml);

However, this compiles clean:

OrderWS.ContractServices txn = new OrderWS.ContractServices ();
XmlNode retxml = txn.OrderContractCert(xml);

I have no idea why the client is expecting an XmlNode.

Jun 22 '06 #7
Unfortunately, that is one of the first things I tried and it did not work.

"chanmm" <ch*****@hotmail.com> wrote in message
news:uq**************@TK2MSFTNGP02.phx.gbl...
Try this:
OrderWS.ContractServices txn = new OrderWS.ContractServices ();
XmlDocument retxml = (XmlDocument) txn.OrderContractCert(xml);

Does it work for you?

chanmm

"Thirsty Traveler" <nf*@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
I have a WebMethod as follows:

[WebMethod]
public XmlDocument OrderContract(XmlDocument doc)
{
return OrderBLL.OrderContract(doc);
}

However, the client is generating a compile error when the following
lines are used:

OrderWS.ContractServices txn = new OrderWS.ContractServices ();
XmlDocument retxml = txn.OrderContractCert(xml);

However, this compiles clean:

OrderWS.ContractServices txn = new OrderWS.ContractServices ();
XmlNode retxml = txn.OrderContractCert(xml);

I have no idea why the client is expecting an XmlNode.


Jun 22 '06 #8


Thirsty Traveler wrote:
Unfortunately, that is one of the first things I tried and it did not work.


It seems (at least with .NET 1.1 from tests) that you get an XmlElement
instead of an XmlDocument so you could use e.g.
XmlNode retxml = txn.OrderContractCert(xml);
XmlDocument doc = retxml.OwnerDocument;
doc.AppendChild(retxml);
and then you can use doc as an XmlDocument.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 22 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by sd | last post: by
6 posts views Thread by rlcavebmg | last post: by
5 posts views Thread by Ray Stevens | last post: by
3 posts views Thread by Khurram | last post: by

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.