Professional Web Applications Themes

How to return my own XML? - ASP.NET Web Services

When I create a web service, and create a web method that returns a string, the output is always framed within a tag that looks like: <string xmlns="http://ewws.example.com/"> </string> What I'd really like to do is eliminate this string and form my own XML to send back. Is this possible? Christopher...

  1. #1

    Default How to return my own XML?

    When I create a web service, and create a web method that returns a string,
    the output is always framed within a tag that looks like:

    <string xmlns="http://ewws.example.com/"> </string>

    What I'd really like to do is eliminate this string and form my own XML to
    send back.

    Is this possible?

    Christopher


    Christopher Ambler Guest

  2. #2

    Default Re: How to return my own XML?

    Dont know if this is a "best practice", but it works for me, Send it back
    via another class. but make sure the secondary class is not the first one
    within the namespace, VS.net doesn't like that, it'll say, "The Class
    Service1 can be designed, but it is not the first class in the file", so
    make sure its something like this:

    public class Service1 : System.Web.Services.WebService

    {

    public Service1()

    {

    InitializeComponent();

    }

    [WebMethod]

    public URLstr ReturnMyURL()

    {

    URLstr ustring = new URLstr();

    ustring.somestring = "ewws.example.com";

    return ustring;

    }

    public class URLstr

    {

    public string somestring;

    }

    Output I got:

    <?xml version="1.0" encoding="utf-8" ?>
    - <URLstr xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://tempuri.org/">
    <somestring>ewws.example.com</somestring>
    </URLstr>
    Hope this helps.

    Kunal



    "Christopher Ambler" <chrisambler.net> wrote in message
    news:eH2l3cWfDHA.2364TK2MSFTNGP09.phx.gbl...
    > When I create a web service, and create a web method that returns a
    string,
    > the output is always framed within a tag that looks like:
    >
    > <string xmlns="http://ewws.example.com/"> </string>
    >
    > What I'd really like to do is eliminate this string and form my own XML to
    > send back.
    >
    > Is this possible?
    >
    > Christopher
    >
    >

    Kunal Das Guest

  3. #3

    Default Re: How to return my own XML?

    Create your own public class with the properties that you
    want to return and return that class instead of a
    string. For example, lets say that your webmethod
    returns customer information. Create the public
    class "Customer" with properties Name, ID, ... all of
    them can be string, int, etc. Then make your webmethod
    return your class, not a string. The result will be
    something like

    <Customer>
    <Name>Test Name</Name>
    <ID>1</ID>
    </Customer>

    Hope this helps.
    >-----Original Message-----
    >Dont know if this is a "best practice", but it works for
    me, Send it back
    >via another class. but make sure the secondary class is
    not the first one
    >within the namespace, VS.net doesn't like that, it'll
    say, "The Class
    >Service1 can be designed, but it is not the first class
    in the file", so
    >make sure its something like this:
    >
    >public class Service1 : System.Web.Services.WebService
    >
    >{
    >
    >public Service1()
    >
    >{
    >
    >InitializeComponent();
    >
    >}
    >
    >[WebMethod]
    >
    >public URLstr ReturnMyURL()
    >
    >{
    >
    >URLstr ustring = new URLstr();
    >
    >ustring.somestring = "ewws.example.com";
    >
    >return ustring;
    >
    >}
    >
    >public class URLstr
    >
    >{
    >
    >public string somestring;
    >
    >}
    >
    >Output I got:
    >
    > <?xml version="1.0" encoding="utf-8" ?>
    >- <URLstr xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    >xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    >xmlns="http://tempuri.org/">
    > <somestring>ewws.example.com</somestring>
    > </URLstr>
    >Hope this helps.
    >
    >Kunal
    >
    >
    >
    >"Christopher Ambler" <chrisambler.net> wrote in message
    >news:eH2l3cWfDHA.2364TK2MSFTNGP09.phx.gbl...
    >> When I create a web service, and create a web method
    that returns a
    >string,
    >> the output is always framed within a tag that looks
    like:
    >>
    >> <string xmlns="http://ewws.example.com/"> </string>
    >>
    >> What I'd really like to do is eliminate this string
    and form my own XML to
    >> send back.
    >>
    >> Is this possible?
    >>
    >> Christopher
    >>
    >>
    >
    >
    >.
    >
    Rimsky Guest

Similar Threads

  1. return SQL ID
    By aredovian in forum Macromedia ColdFusion
    Replies: 0
    Last Post: March 18th, 06:44 PM
  2. return xml
    By Poppy in forum ASP.NET Web Services
    Replies: 3
    Last Post: April 27th, 04:01 PM
  3. goToNetPage, return or not return
    By GONS in forum Macromedia Director Basics
    Replies: 1
    Last Post: January 16th, 08:44 PM
  4. Return Key
    By Ethan in forum Mac Portable
    Replies: 0
    Last Post: July 14th, 11:43 PM
  5. Return to Tab
    By Joe Fallon in forum Microsoft Access
    Replies: 0
    Last Post: July 12th, 04:53 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139