CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: XmlInclude

  1. #1
    Join Date
    May 2003
    Location
    Corvallis, OR
    Posts
    315

    XmlInclude

    I have 2 classes that are shared between my webservice and my client app (both in c#)...

    Code:
    public class ImageFile
    {
        private string m_sFileName;
        private csAWCDefines.UploadType m_uploadType;
    
        public ImageFile()
        {
    
        }
    
        public ImageFile(string sFileName, csAWCDefines.UploadType uploadType)
        {
            m_sFileName = sFileName;
            m_uploadType = uploadType;
        }
    
        public string FileName
        {
            get { return m_sFileName; }
        }
    
        public csAWCDefines.UploadType UploadType
        {
            get { return m_uploadType; }
        }
    }
    AND
    Code:
    public class ArrayContainer
    {
        public System.Collections.ArrayList m_aryFiles;
    
        public ArrayContainer()
        {
            m_aryFiles = new System.Collections.ArrayList();
        }
    }
    I fill the ArrayContainer::m_aryFiles like this in a [WebMethod]...
    Code:
    [WebMethod]
    public bool FillArry(ref ArrayContainer aryContainer)
    {
    	string sImage1 = @"test1.img";
    	string sImage2 = @"test2.img";
    	aryContainer.m_aryFiles.Add(new ImageFile(sImage1, csAWCDefines.UploadType.uploadClean));
    	aryContainer.m_aryFiles.Add(new ImageFile(sImage2, csAWCDefines.UploadType.uploadClean));
    	return true;
    }
    I am passing an instance of the ArrayContainer class by ref from my client to my webservice.

    Instead of returning as planned, I get the following error...
    Additional information: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type ImageFile was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
    I think XmlInclude might be the answer to my problem, but I'm not sure how to implement it in this case. Anyone have any suggestions? Do I implement XmlInclude as part of the ImageFile class? The ArrayContainer class? Neither? Where/how do I implement it correctly?

  2. #2
    Join Date
    May 2003
    Location
    Corvallis, OR
    Posts
    315

    Re: XmlInclude

    I ended up removing the reference to the ArrayList type and replacing it with a direct reference to an ImageList[] class array. Like this...
    Code:
    public bool FillArry(ImageList[]  aryContainer)
    Instead of
    Code:
    public bool FillArry(ref ArrayContainer aryContainer)
    I also had to add 1 simple line on top of my webservice fxn signature...
    Code:
    [XmlInclude(typeof(ImageFile))] //this makes xml recognize ImageFile type
    public bool FillArry(ImageList[]  aryContainer)
    The solution is well documented here in "Listing 4. Facade to expose the simple array Product[]

    Hope this helps the next guy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured