How to return a Document object in Web services

I’m a developer in a Database Solution company in Australia. Currently, I am evaluating the Aspose.Words for a project. I can not return the Document object through web services.

There is always an exception, when I open the web services though brower:
You must implement the Add(System.Object) method on Aspose.Words.Document because it inherits from IEnumerable.
This is the code:

[WebMethod]
public Document GenerateWord(string ValuationReference)
{
    Aspose.Words.Demos.Viewer pathv = new Aspose.Words.Demos.Viewer();
    string licenseFile = @"C:\Program Files\Aspose\Aspose.Words\Demos\Aspose.Words.Demos\bin\Aspose.Words.lic";
    if (System.IO.File.Exists(licenseFile))
    {
        //This shows how to license Aspose.Words, if you don't specify a license, 
        //Aspose.Words works in evaluation mode.
        Aspose.Words.License license = new Aspose.Words.License();
        license.SetLicense(licenseFile);
    }

    DinnerInvitationDemo demo = new DinnerInvitationDemo();
    demo.Init(pathv.MapPath("."));
    Document doc = demo.Generate(ValuationReference);
    return doc;
}

When I change the definition of the function to void, everything is all right. Should I serialize the Document object or there is something I don’t know ? Can anybody help me out?

Here is a note from MSDN which explains what is going on:

The XmlSerializer gives special treatment to classes that implement IEnumerable or ICollection. A class that implements IEnumerable must implement a public Add method that takes a single parameter. The Add method’s parameter must be of the same type as is returned from the Current property on the value returned from GetEnumerator, or one of that type’s bases. A class that implements ICollection (such as CollectionBase) in addition to IEnumerable must have a public Item indexed property (indexer in C#) that takes an integer, and it must have a public Count property of type integer. The parameter to the Add method must be the same type as is returned from the Item property, or one of that type’s bases. For classes implementing ICollection, values to be serialized will be retrieved from the indexed Item property, not by calling GetEnumerator.

But the document class in Aspose.Words was never meant to be serialized directly. To pass the document in web you can either save it to the memory stream first using Document.Save(Stream, SaveFormat) method overload and then return MemoryStream in a web method. Or send it in HTTP response using Document.Save(String, SaveFormat, SaveType, HttpResponse) method overload.

Best regards,

Thanks for your help.

There is an addtional question: after I return the memorystream, how can I convert it to a doc on client site.

Thanks for your help.
There is an addtional question: after I return the memorystream, how can I convert it to a doc on client site.

I have found the solution.

Thanks.