How to return my own XML?

Ask a Question related to ASP.NET Web Services, Design and Development.

  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. Similar Questions and Discussions

    1. Return me
      :confused; I need the html for Dreamweaver 8 that will return a person back to a previous page. They could be coming from any number of previous...
    2. return SQL ID
      one way (I believe to be the best way) is to use a stored procedure and set an output variable to the new SQL ID. a second way is to use a...
    3. return xml
      The following function is used in my webservice which returns a dataset. I now need to return the dataset as xml and have no idea how to do it....
    4. goToNetPage, return or not return
      hi, I have read in the director's help the netDone() command indicates whether a background loading operation (such as getNetText,...
    5. Return Key
      This may sound like an odd question, but does anyone have a "return" key from a Wallstreet powerbook that they don't need? All i need is the key,...
  3. #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" <chris@ambler.net> wrote in message
    news:eH2l3cWfDHA.2364@TK2MSFTNGP09.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

  4. #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" <chris@ambler.net> wrote in message
    >news:eH2l3cWfDHA.2364@TK2MSFTNGP09.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

Posting Permissions

  • You may not post new threads
  • You may 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