Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old November 12th, 2005, 04:39 AM
hudris@hotmail.com
Guest
 
Posts: n/a
Default Web Service returning class in XML with namespace information

Hi All,

I am trying to return a class from a Webservice without having to deal
with xmlns:xsd and xmlns:xsi. I have to get rid of those because this
is sent over an expensive network and I'd like to minimize the cost.

I've seen posts that show how to do this, but it didn't work for me.
Here is what I've done so far:

public class clsQueTrans
{
public string label;
public byte[] data;
}
[WebMethod]
public clsQueTrans GetNextMessage(string queueName)
{
clsQueTrans qt = new clsQueTrans();
qt.label = "fing";
qt.data = new byte[10];
for(int i = 0; i < 10; i++)
qt.data[i] = (byte)i;

// this is to tell XmlSerializer to use UTF8 encoding
System.IO.MemoryStream ms = new System.IO.MemoryStream();
XmlSerializer ser=new XmlSerializer(typeof(clsQueTrans));
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("","");
ser.Serialize(ms, qt, ns);

return qt;
}


If I set the return type to void, nothing is sent to the browser (I use
GET to test the service), Console.Out doesn't do the trick.
ser.Serialize(Console.Out, qt, ns);
return;

If I return the class instance (as in the example) then I get the
dreaded namespaces.

If I return a string like this:
string x = System.Text.Encoding.ASCII.GetString(ms.GetBuffer( ));
return x;

then I get what I want, but it's xml mebedded in xml. I need the xml
itself.

How can I get the web service to output something like the string "x".


What am I missing here?

Thanks,
A.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.