Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6906761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:21:04+00:00 2026-05-27T08:21:04+00:00

I’m working on a server-client application. The communication is done using webservice webmethods. Both

  • 0

I’m working on a server-client application. The communication is done using webservice webmethods. Both server and client are written in C#. I’ve been fighting with it for few days now but I couldn’t solve it.

I have problem to send complex classes through webservice – I tried many things so far but none of them work.

Each webmethod returns ServiceResult class which looks like this:

    public class ServiceResult
    {
        public ResultStatus Status;
        public object ResultObject;

        public ServiceResult(ResultStatus status, object resultObject)
        {
            Status = status;
            ResultObject = resultObject;
        }
    }

ResultStatus is enum, ResultObject is actual returned value. The problem came when I had tried to send complex classes through webservice.

For example, I have abstract class Job, which has got private elements.

public abstract class Job : IComparable<Job>
{
    public static readonly int DefaultDelay = 5000;

    private int _jobID;
    private int _referringID;
    private JobType _jobType;
    protected JobState _jobState;
    private JobPriority _jobPriority;
    [...]   
}

But when I try send class which inherits Job class (let’s call it JobA) over webmethod I have errors. Because I have no explicit JobA return type in any webmethod, when I call my webmethod I get an error:

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 Job[] may not be used in
this context.

That was about first error. Now there is another problem with different class, where error looks like this (again, when calling a webmethod):

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 was not expected. Use the
XmlInclude or SoapInclude attribute to specify types that are not
known statically.

When I add [SoapInclude(typeof(MyClass))] it has no difference, but using XmlInclude instead makes my ServiceResult.ResultObject array of XmlNodes.

I think both problems are about serialization but I don’t know how to solve them. Basically, my question is: how should I pass custom objects from server to client through webmethod in such a way so I can use them as object (I’d like to cast this ServiceResult.ResultObject to class and use it like an casual instance of that class)? What is the best way to do that?

Could anyone suggest any solution for it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:21:05+00:00Added an answer on May 27, 2026 at 8:21 am

    Based on the initial error message, it sounds like you may have a property that is an array or collection of Job in the class you are trying to serialize, which will cause the exception that you are seeing.

    If this property is not supposed to be serialized, then you can decorate it with the XmlIgnore attribute.

    Also, when I am trying to debug issues with web service serialization, what I generally do is use XmlSerializer to serialize instances of my web service classes before trying to hook them up to web methods. Sometimes you can get more explicit information on what failed and see the serialized output to determine where elements might not be serialized as you expect them to be.

    Here is a little test method that you can use for this:

        /// <summary>
        /// This method serializes objects to an XML string using the XmlSerializer
        /// </summary>
        /// <returns></returns>
        /// <remarks></remarks>
        public string SerializeObjectToXMLString(object theObject)
        {
            // Exceptions are handled by the caller
    
            using (System.IO.MemoryStream oStream = new System.IO.MemoryStream())
            {
                System.Xml.Serialization.XmlSerializer oSerializer = new System.Xml.Serialization.XmlSerializer(theObject.GetType());
    
                oSerializer.Serialize(oStream, theObject);
    
                return Encoding.Default.GetString(oStream.ToArray());
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have thousands of HTML files to process using Groovy/Java and I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.