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 8673803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:33:13+00:00 2026-06-12T19:33:13+00:00

I’m trying to use WCF service with raw messages. 1) WCF service code: [DataContract]

  • 0

I’m trying to use WCF service with raw messages.

1) WCF service code:

[DataContract]
public class Person
{
    [DataMember]
    public int Id { get; set; }

    [DataMember]
    public string FirstName { get; set; }

    [DataMember]
    public string LastName { get; set; }
}

public static List<Person> CreateEmployees()
{
    List<Person> lstPersons = new List<Person>()
    {
        new Person { Id = 1, FirstName = "Andrey", LastName = "Andreyev" },
        new Person { Id = 2, FirstName = "Sergey", LastName = "Sergeyev" }
    };

    return lstPersons;
}

[ServiceContract]
public interface ITestService
{
    [OperationContract(Action = TestService.RequestAction, ReplyAction = TestService.ReplyAction)]
    Message GetPersonById(Message id);
}

public class TestService : ITestService
{
    public const String ReplyAction = "http://localhost:4249/Message_ReplyAction";
    public const String RequestAction = "http://localhost:4249/Message_RequestAction";

    public Message GetPersonById(Message id)
    {
        string firstName = Employees.CreateEmployees().First(e => e.Id == id.GetBody<int>()).FirstName;
        Message response = Message.CreateMessage(id.Version, ReplyAction, firstName);
        return response;
    }
}

2) Client code:

static void Main(string[] args)
{
    TestServiceClient client = new TestServiceClient();
    String RequestAction = "http://localhost:4249/Message_RequestAction";
    int value = 1;
    Message request = Message.CreateMessage(MessageVersion.Default, RequestAction, value);
    Message reply = client.GetPersonById(request);
    string firstName = reply.GetBody<string>();

    Console.WriteLine(firstName);
    client.Close();
}

When I run the client with: int value = 1 everything works fine. But, when I use: int value = 2 I get the following error:

System.Runtime.Serialization.SerializationException was unhandled
Message=”Error in line 1 position 276. Expecting element ‘string’ from namespace ‘http://schemas.microsoft.com/2003/10/Serialization/‘.. Encountered ‘Element’ with name ‘Fault’, namespace ‘http://www.w3.org/2003/05/soap-envelope‘. ”
Source=”System.Runtime.Serialization”
StackTrace:
at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName)
at System.Runtime.Serialization.XmlObjectSerializer.ReadObject(XmlDictionaryReader reader)
at System.ServiceModel.Channels.Message.GetBody[T](XmlObjectSerializer serializer)
at System.ServiceModel.Channels.Message.GetBodyT
at ClientTestService.Program.Main(String[] args) in E:\Projekti\WCF\Parus\ClientTestService\ClientTestService\Program.cs:line 22
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

At line:

string firstName = reply.GetBody<string>();

The service is started and I’ve added the service reference through “Add Service Reference…” in VS2008. I use .NET Framework 3.5.

I’m not sure why I’m getting this error.

When I don’t use Message class everything works fine. I mean on this:

[ServiceContract]
public interface ITestService
{
    [OperationContract]
    Person GetPersonById(int id);
}

public class TestService : ITestService
{
    public Person GetPersonById(int id)
    {
        Person person = Employees.CreateEmployees().First(e => e.Id == id);
        return person;
    }
}

2) Client code:

static void Main(string[] args)
{
    TestServiceClient client = new TestServiceClient();
    int value = 1;
    Person person = client.GetPersonById(value);

    Console.WriteLine(person.FirstName);
    client.Close();
}

I would be really thankful if somebody can help.

  • 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-06-12T19:33:14+00:00Added an answer on June 12, 2026 at 7:33 pm
    Message reply = client.GetPersonById(request); 
    if(reply.IsFault)
      throw new GoransException(reply.toString());
    string firstName = reply.GetBody<string>();
    //...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.