error with namespace

R

RadhaKrishna

I created a small web service with a single method that
returns XmlElement back to the client. This method is
working fine if I return string using OuterXml property,
but when I am trying to return XmlElement it is throwing
error. could anybody give me hint, what could be the
problem..


thanx in advance
RK



webservice is something like this..

[WebService(Namespace="http://www.xyz.com/myService")]
public class myWebService:System.Web.Services.WebService
{

[WebMethod]
public XmlElement getXML(string strNumber)
{
XmlDocument objXML = new XmlDocument();
objXML.LoadXml("<topElement></topElement>");

/**nodeOne and nodeTwo are coming from dll
* component using some methods */

objXML.DocumentElement.AppendChild(nodeOne);
objXML.DocumentElement.AppendChild(nodeTwo);

return objXML.DocumentElement;

}

}

It is throwing an error like

System.InvalidOperationException: There was an error
generating the XML document. --->
System.ArgumentException: Cannot use a prefix with an
empty namespace.
at System.Xml.XmlTextWriter.WriteStartElement(String
prefix, String localName, String ns)
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlElement.WriteContentTo(XmlWriter w)
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlElement.WriteContentTo(XmlWriter w)
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at
System.Xml.Serialization.XmlSerializationWriter.WriteElemen
t(XmlNode node, String name, String ns, Boolean any)
at
System.Xml.Serialization.XmlSerializationWriter.WriteElemen
tLiteral(XmlNode node, String name, String ns, Boolean
isNullable, Boolean any)
at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializat
ionWriter1.Write1_Item(Object o)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize
(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces
namespaces)
at System.Xml.Serialization.XmlSerializer.Serialize
(TextWriter textWriter, Object o, XmlSerializerNamespaces
namespaces)
at System.Xml.Serialization.XmlSerializer.Serialize
(TextWriter textWriter, Object o)
at System.Web.Services.Protocols.XmlReturnWriter.Write
(HttpResponse response, Stream outputStream, Object
returnValue)
at
System.Web.Services.Protocols.HttpServerProtocol.WriteRetur
ns(Object[] returnValues, Stream outputStream)
at
System.Web.Services.Protocols.WebServiceHandler.WriteReturn
s(Object[] returnValues)
at
System.Web.Services.Protocols.WebServiceHandler.Invoke()
at
System.Web.Services.Protocols.WebServiceHandler.CoreProcess
Request()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top