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

  • Home
  • SEARCH
  • 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 5993191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:38:23+00:00 2026-05-22T23:38:23+00:00

I have application based on this tutorial Method I use to get user list

  • 0

I have application based on this tutorial

Method I use to get user list from service:

public class PBMBService : IService
{
    public ServiceResponse UserList()
    {
        try
        {
            sql.Open();
            List<User> result = new List<User>();

            //filling list from database

            return new ServiceResponse(SRFlag.OK, result);
        }
        catch (Exception ex)
        {
            return new ServiceResponse(SRFlag.EXCEPTION, ex);
        }


    }

//other methods
}

Service main function:

class Program
{
    static void Main(string[] args)
    {
        Uri baseAddress = new Uri("http://localhost:8000/PBMB");

        ServiceHost selfHost = new ServiceHost(typeof(PBMBService), baseAddress);

        try
        {
            selfHost.AddServiceEndpoint(
                typeof(IService),
                new WSHttpBinding(),
                "PBMBService");

            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
            smb.HttpGetEnabled = true;
            selfHost.Description.Behaviors.Add(smb);

            selfHost.Open();
            Console.WriteLine("Serwis gotowy.");
            Console.WriteLine("Naciśnij <ENTER> aby zamknąć serwis.");
            Console.WriteLine();
            Console.ReadLine();


            selfHost.Close();
        }
        catch (CommunicationException ce)
        {
            Console.WriteLine("Nastąpił wyjątek: {0}", ce.Message);
            selfHost.Abort();
        }
    }
}

Other classes are in
Classes.cs

namespace PBMB
{
public enum SRFlag { OK, EXCEPTION };

[DataContract]
public class ServiceResponse
{
    private SRFlag _flag;
    private Object _content;

    public ServiceResponse(SRFlag srf, Object c)
    {
        _flag = srf;
        _content = c;
    }

    [DataMember]
    public SRFlag Flag
    {
        set { _flag = value; }
        get { return _flag; }
    }

    [DataMember]
    public Object Content
    {
        set { _content = value; }
        get { return _content; }
    }
}

[DataContract]
public class User
{
    [DataMember]
    public string Login { get; set; }
    [DataMember]
    public string FirstName { get; set; }
    [DataMember]
    public string MiddleName { get; set; }
    [DataMember]
    public string LastName { get; set; }
    [DataMember]
    public string Email { get; set; }
}
}

My question is: why I can’t send anything that is not generic type?
I need to send List<User> or User[] but I can’t even send int[2] (sending int or string is possible).

When I try to send List from service to client, service works but I get exception in client:

An error occurred while receiving the HTTP response to http://localhost:8000/PBMB/PBMBService.  
This could be due to the service endpoint binding not using the HTTP protocol.  
This could also be due to an HTTP request context being aborted by the server  
(possibly due to the service shutting down). See server logs for more details.  
  • 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-22T23:38:24+00:00Added an answer on May 22, 2026 at 11:38 pm

    I guess this happens because User class is declared as DataContract and data serializer is able to serialize and deserialize it.

    However, it is a very bad idea to declare object as a part of response that is returned. You should always specify the type that is returned. Returning object is against message passing principles. Service client should be able to obtain all the information needed from wsdl and it is basically impossible if you define part of the response as object (what kind of object? .net specific object? etc.) Message passing principles are simply different than object oriented principles.

    Also if you want to return exceptions to clients check FaultException.

    UPDATE:

    How to solve it?

    1. Change your design – don’t expect you can just send any object. This is a wrong assumption when it comes to SOA and message passing.
    2. If you want to send objects of basic types such as int, string just declare in your response that you will return public string Content or public int Number – just like you did but state the type explicitly (don’t use object). If you want to return custom class i.e. User, declare it just like you did (DataContract, DataMember, etc – however it is not necessary) and just write public User Content. It will work and the client will know what to expect in service response.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have application based on this tutorial Method I use to test connection to
I have simple WCF Service Application (based on this tutorial http://msdn.microsoft.com/en-us/library/ms734712.aspx ). Is it
I have simple WCF Service Application (based on this tutorial : Getting Started ).
I have this application I made on a utility based app. How would I
I have installed pylons based application from egg, so it sits somewhere under /usr/lib/python2.5/site-packages.
I have an view-based application where the user can do a lot of customization
I have an application that connects via https to a SOAP-based web service that
Based on this tutorial I have built a page which functions correctly. I added
I'm following this tutorial for adding EULA to my Android application, but i have
I have created an iPhone application based on an OpenGL view. Now I would

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.