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.