Consuming XML Web Service

G

Guest

Hi!

Please, could You advice me to complete the following task:

We have a Web Service that returns XML document with some data about our
customers.

[WebMethod]
public XmlDocument getCustInfo()
{
//some implementation
}

I am trying to parse that document and to print customers' names and email
addresses. If some custorem does not have an email address I print "no email
address found". I have to go throught the xml document and it's nodes using
eg. foreach statement and resolve whether customer has an email address with
if else statements.

Please, could You tell me, how can I load this Xml document which WebService
provides? I tried to load it into XmlDocument object with Load method, but
beacause it is not xml file I get errors. The help is very much appreciated.

Thanks.

Peter
 
G

gaidar

Hi, Peter,

You can get text from your Web Service. I see no problem in transmitting
XML-formatted string. Anyway, you can get string data and produce XML
document manually.
Could you explain your problem? I just don't understand...

Best Regards,
Gaidar
 
G

Guest

Hello!

Thank you for the reply! I managed to resolve the issue. I just had to use
XmlNode, eg.

XmlNode custInfo;
custInfo = service.getCustInfo();

foreach (XmlNode Node in custInfo)

if (Node.ChildNodes[1].InnerText !="") //No email found

Now I can process the xml document returned by web service.

Peter

gaidar said:
Hi, Peter,

You can get text from your Web Service. I see no problem in transmitting
XML-formatted string. Anyway, you can get string data and produce XML
document manually.
Could you explain your problem? I just don't understand...

Best Regards,
Gaidar

Peter said:
Hi!

Please, could You advice me to complete the following task:

We have a Web Service that returns XML document with some data about our
customers.

[WebMethod]
public XmlDocument getCustInfo()
{
//some implementation
}

I am trying to parse that document and to print customers' names and email
addresses. If some custorem does not have an email address I print "no
email
address found". I have to go throught the xml document and it's nodes
using
eg. foreach statement and resolve whether customer has an email address
with
if else statements.

Please, could You tell me, how can I load this Xml document which
WebService
provides? I tried to load it into XmlDocument object with Load method, but
beacause it is not xml file I get errors. The help is very much
appreciated.

Thanks.

Peter
 
K

Kevin Spencer

Please, could You tell me, how can I load this Xml document which
WebService
provides? I tried to load it into XmlDocument object with Load method, but
beacause it is not xml file I get errors. The help is very much
appreciated.

What errors are you getting? Here's why I'm asking:

According to your WebMethod declaration, it returns a
System.Xml.XmlDocument. I don't believe this class is serializable. It isn't
marked as serializable It is important to note the difference between an
XmlDocument class and an XML Document. An XmlDocument class is a class for
working with XMLDocuments.

A WebMethod returns an instance of a class, as an XML Document (NOT a
System.Xml.XmlDocument). The class must be serializable. At the client end,
the class is deserialized back into a class. So, as you can see, it isn't
necessary to create an XML Document; the response is one already. It is
necessary to create a serializable class that can be returned and
de-serialized back into a class.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

Peter said:
Hi!

Please, could You advice me to complete the following task:

We have a Web Service that returns XML document with some data about our
customers.

[WebMethod]
public XmlDocument getCustInfo()
{
//some implementation
}

I am trying to parse that document and to print customers' names and email
addresses. If some custorem does not have an email address I print "no
email
address found". I have to go throught the xml document and it's nodes
using
eg. foreach statement and resolve whether customer has an email address
with
if else statements.

Please, could You tell me, how can I load this Xml document which
WebService
provides? I tried to load it into XmlDocument object with Load method, but
beacause it is not xml file I get errors. The help is very much
appreciated.

Thanks.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top