Can a web service produce bad XML?

N

needin4mation

Hi, I have a simple web service. In my HelloWorld() all it does it
retreive about five last and first names from a database. It then
returns the DataSet.

When I run the Web Service in VS 2003 and I get the general IIS web
service page I press "Invoke" and the web service runs and brings back
what looks like a schema and an XML page.

I also have a consumer. But when I run it I get that tags don't match
when I attempt to use the XmlTextReader.read().

I took the XML data out of the web service and cleaned it up (it had
diffgr, etc. in it) and ran my consumer against the same data in file
form and it worked.

Here is my question:

When I run the web service it brings back more than just the XML data
from the database. Was I supposed to do something besided just using
XmlTextReader to parse the web service page?

Here is my consumer:

string table = null;
string last_name = null;
string first_name = null;
StringBuilder sb = new StringBuilder();
try
{
sb.Append("<ul>");
XmlTextReader reader = new
XmlTextReader("http://localhost/myWebService/employeeInfo.asmx");
//XmlTextReader reader = new
XmlTextReader(Server.MapPath("./test.xml"));
reader.MoveToContent();

while (reader.Read())
{

if (reader.Name == "Table" && reader.NodeType ==
XmlNodeType.Element)
{
sb.Append("<li>");
}
if (reader.Name == "last_name")
{
last_name = reader.ReadString();
}
if (reader.Name == "first_name")
{
first_name = reader.ReadString();
}
if (reader.Name == "Table" && reader.NodeType ==
XmlNodeType.EndElement)
{
sb.Append("Last: " + last_name + ", " + "First: " + first_name);
sb.Append("<BR>");
sb.Append("</li>");
}

}
sb.Append("</ul>");
Label1.Text = sb.ToString();
reader.Close();

Thank you for any help.
 
H

Henrique Mello

Well......
i really dont know if you doing this in a super advanced way or you
have nerver used before but the way i use a WebService is:

serv = new MyServer.MyWebserver();
serv.PreAuthenticate = false;
serv.Url = ConfigurationSettings.AppSettings["MyWebServerPath"];
serv.Credentials = CredentialCache.DefaultCredentials;
serv.Timeout =
Convert.ToInt32(ConfigurationSettings.AppSettings["WebServiceTimeOut"]);

If you are trying something more advanced then that never mind my post
 
N

needin4mation

Henrique said:
Well......
i really dont know if you doing this in a super advanced way or you
have nerver used before but the way i use a WebService is:

serv = new MyServer.MyWebserver();
serv.PreAuthenticate = false;
serv.Url = ConfigurationSettings.AppSettings["MyWebServerPath"];
serv.Credentials = CredentialCache.DefaultCredentials;
serv.Timeout =
Convert.ToInt32(ConfigurationSettings.AppSettings["WebServiceTimeOut"]);

If you are trying something more advanced then that never mind my post

Thanks. The funny thing is that when I run it similar to what you
have, but I attach the results to a datagrid it works. But if I use
the XmlTextReader, it fails.

If I return a DataSet from my web service, can I not use the
XmlTextReader to view the results like above? Or should I have a
different method of returning the data than dataset if I want my
clients to view the data. They may not have ASP.NET and have trouble
with the DataSet object.

The original example I had seen did not have a result DataSet returned.
It was just an RSS feed, so it must just be XML alone. It's all just
bits and pieces right now, so I am probably mixing things up quite a
bit.
 
H

Henrique Mello

Well,
The thing is if you send a DATASET through a webservice, the web
service turns it in a compreensive XML. but still if you client have
dificult reading it, you may consider using sending and array of
Object. Like : you create and VO (Value Object) Product
public class Produto
{
string Name;
string price;
}

and return products[], if the other side have a developer there is no
way they can´t handle the return of you web service.
 
N

needin4mation

Henrique said:
Well,
The thing is if you send a DATASET through a webservice, the web
service turns it in a compreensive XML. but still if you client have
dificult reading it, you may consider using sending and array of
Object. Like : you create and VO (Value Object) Product
public class Produto
{
string Name;
string price;
}

and return products[], if the other side have a developer there is no
way they can´t handle the return of you web service.

So using a DataSet is not good unless everyone is playing with ASP.NET?
Now I am really lost. How do I return it as just XML that anyone can
read?
 
H

Henrique Mello

If you use a DATASET, everyone can read, cause the XML the webservice
generate can be read in all the languages I know.
But the best way would be doing that as a collection of objects, as the
JAVA best practices says got it?
 
H

Henrique Mello

Well, i still dont got your problem now.
Ignore the XML part, the web service returns a variable, now how the
other side retrive this variable is more simple than you can imagine.

The best practices tell you to return Objects like the one I showed you
but you can return almost anything.

If you think your client will have a problem if you return an DataSet
ask him first. Cause I havent got any problem with mine clients
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top