G
George Ter-Saakov
I wrote webservice with one method Test.
When i am trying to return a simple string it works form test client.
When i am trying to return an XML as a string the client throws an error.
"An unhandled exception of type 'System.InvalidOperationException' occurred
in system.xml.dll"
When i test service with a browser it works. Test2 returns an XML.
Here is the code i use for WebService (Test2 works, Test1 does not).
[WebMethod]
public string Test2(string sBod)
{
return "Hello from ShipmentStatus";
}
[WebMethod]
public string Test1(string sBod)
{
return GetXml("Hello from ShipmentStatus");
}
public string GetXml( string sXml)
{
MemoryStream mem = new MemoryStream();
XmlTextWriter xml = new XmlTextWriter(mem,
System.Text.UTF8Encoding.UTF8);
xml.Formatting = Formatting.Indented;
xml.WriteStartDocument();
xml.WriteElementString("TEST", sXml);
xml.WriteEndDocument();
xml.Close();
byte[] buf = mem.GetBuffer();
return System.Text.UTF8Encoding.UTF8.GetString(buf,0, buf.Length);
}
-----Client code ---
Service1 serv = new Service1();
string sreply1 = serv.Test1("sadf");
string sreply2 = serv.Test2("sadf");
When i am trying to return a simple string it works form test client.
When i am trying to return an XML as a string the client throws an error.
"An unhandled exception of type 'System.InvalidOperationException' occurred
in system.xml.dll"
When i test service with a browser it works. Test2 returns an XML.
Here is the code i use for WebService (Test2 works, Test1 does not).
[WebMethod]
public string Test2(string sBod)
{
return "Hello from ShipmentStatus";
}
[WebMethod]
public string Test1(string sBod)
{
return GetXml("Hello from ShipmentStatus");
}
public string GetXml( string sXml)
{
MemoryStream mem = new MemoryStream();
XmlTextWriter xml = new XmlTextWriter(mem,
System.Text.UTF8Encoding.UTF8);
xml.Formatting = Formatting.Indented;
xml.WriteStartDocument();
xml.WriteElementString("TEST", sXml);
xml.WriteEndDocument();
xml.Close();
byte[] buf = mem.GetBuffer();
return System.Text.UTF8Encoding.UTF8.GetString(buf,0, buf.Length);
}
-----Client code ---
Service1 serv = new Service1();
string sreply1 = serv.Test1("sadf");
string sreply2 = serv.Test2("sadf");