Can a web service produce bad XML?

Discussion in 'ASP .Net' started by needin4mation@gmail.com, Jan 9, 2006.

  1. Guest

    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.
    , Jan 9, 2006
    #1
    1. Advertising

  2. 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
    Henrique Mello, Jan 9, 2006
    #2
    1. Advertising

  3. Guest

    Henrique Mello wrote:
    > 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.
    , Jan 9, 2006
    #3
  4. 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.
    Henrique Mello, Jan 9, 2006
    #4
  5. Guest

    Henrique Mello wrote:
    > 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?
    , Jan 9, 2006
    #5
  6. 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?
    Henrique Mello, Jan 9, 2006
    #6
  7. Guest

    Henrique Mello wrote:
    > 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?


    I'm not sure what to search on. Do you have a link, perhaps?

    I tried this, but nothing was obvious:

    http://www.google.com/search?source...GGLG:en&q=xml web services collection objects
    , Jan 9, 2006
    #7
  8. 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
    Henrique Mello, Jan 9, 2006
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    850
  2. SV
    Replies:
    1
    Views:
    609
    Mukul Gandhi
    Aug 16, 2005
  3. Replies:
    5
    Views:
    449
    Luc The Perverse
    Oct 27, 2006
  4. rantingrick
    Replies:
    44
    Views:
    1,170
    Peter Pearson
    Jul 13, 2010
  5. Leo Violette
    Replies:
    0
    Views:
    1,001
    Leo Violette
    Apr 17, 2009
Loading...

Share This Page