views:

27

answers:

2

I'm getting an error after acessing my webservice like:

Server Error in '/' Application.

Type 'System.Xml.XmlDocument' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. See the Microsoft .NET Framework documentation for other supported types.

The SRC is fairly easy:

public interface IService1
{
 [OperationContract]
 [WebGet(ResponseFormat = WebMessageFormat.Xml)]
 XmlDocument TwitterGetPublicTimeline();
}

and the WebService:

    public XmlDocument TwitterGetPublicTimeline()
    {            
        var t = new Yedda.Twitter();
        return t.GetPublicTimelineAsXML();
    }

if I return it has a string the document is preceded by " wich is not acceptable.. :|

+2  A: 

XmlDocument isn't serializable (as you've found out). You should also avoid returning framework types on a WS call for interop. Best thing to do is return the xml as a string and let the client load it into a client specific DOM or return a serializable custom type.

Daz Lewis
+2  A: 

You can change your method to

    public String TwitterGetPublicTimeline()
    {
        var t = new Yedda.Twitter();
        return t.GetPublicTimelineAsXML().InnerXml;
    }

to return just a String and on the client side, use XmlDocument.LoadXml() method to convert it back to XmlDocument.

decyclone
if I do that it adds automatically the tag <string> and some microsoft namespace..
Pedro
Yes, that is because of `ResponseFormat = WebMessageFormat.Xml`. Is your client a .Net client? Because if it is, it should work! Otherwise, you can write some code to read the text inside the generated `XML` and you can rely on it, because it will be same everytime.
decyclone