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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:43:52+00:00 2026-05-11T10:43:52+00:00

I am proper struggling getting that "magic" moment when WCF is configured nicely and

  • 0

I am proper struggling getting that "magic" moment when WCF is configured nicely and jQuery is structuring its requests/understanding responses nicely.

I have a service:

<%@ ServiceHost Language="C#" Debug="true" Service="xxx.yyy.WCF.Data.ClientBroker" Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory"  %> 

This was recommended by the man Rick Strahl to avoid having to define the behaviours within Web.config.

My interface for the WCF service sits in another assembly:

namespace xxx.yyy.WCF.Data {            [ServiceContract(Namespace = "yyyWCF")]      public interface IClientBroker     {         [OperationContract]                  [WebInvoke(Method="POST",BodyStyle=WebMessageBodyStyle.Wrapped,ResponseFormat=WebMessageFormat.Json)]         IClient GetClientJson(int clientId);         } } 

The concrete service class is:

namespace xxx.yyy.WCF.Data {     [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]     class ClientBroker : IClientBroker      {         public IClient GetClientJson(int clientId)         {             IClient client=new Client();              // gets and returns an IClient             return client;         }     } } 

My IClient is an Entity Framework class so is decorated with DataContract/DataMember attributes appropriately.

I am trying to call my WCF service using the methods outlined on Rick Strahl’s blog at http://www.west-wind.com/weblog/posts/324917.aspx (the "full fat" version). The debugger jumps into the WCF service fine (so my jQuery/JSON is being understood) and gets the IClient and returns it. However, when I return the response, I get various useless errors. The errors I am getting back don’t mean much.

I am using POST.

Am I right to be using an Interface instead of a concrete object? As it does get into the WCF service, it does seem to be the encoding of the result that is failing.

Does anyone have any ideas?

  • 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. 2026-05-11T10:43:53+00:00Added an answer on May 11, 2026 at 10:43 am

    At first glance there are three problems with your code:

    1: you should use the ServiceKnownTypeAttribute to specify known types when exposing only base types in your operation contracts:

    [ServiceContract(Namespace = 'yyyWCF')]      public interface IClientBroker {     [OperationContract]     [ServiceKnownType(typeof(Client))]     [WebInvoke(         Method='GET',         BodyStyle=WebMessageBodyStyle.WrappedRequest,         ResponseFormat=WebMessageFormat.Json)]     IClient GetClientJson(int clientId);  } 

    2: You should use WebMessageBodyStyle.WrappedRequest instead of WebMessageBodyStyle.Wrapped because the latter is not compatible with WebScriptServiceHostFactory.

    3: IMHO using Method=’GET’ would be more RESTful for a method called GetClientJson than Method=’POST’

    Another advice I could give you when working with WCF services is to use SvcTraceViewer.exe bundled with Visual Studio. It is a great tool for debugging purposes. All you need is to add the following section to your app/web.config:

      <system.diagnostics>     <sources>       <source name='System.ServiceModel'               switchValue='Information, ActivityTracing'               propagateActivity='true'>         <listeners>           <add name='sdt'               type='System.Diagnostics.XmlWriterTraceListener'               initializeData= 'WcfDetailTrace.e2e' />         </listeners>       </source>     </sources>   </system.diagnostics> 

    Then invoke the web method and WcfDetailTrace.e2e file will be generated in your web site root directory. Next open this file with SvcTraceViewer.exe and you will see lots of useful information. For example it could say:

    Cannot serialize parameter of type ‘MyNamespace.Client’ (for operation ‘GetClientJson’, contract ‘IClientBroker’) because it is not the exact type ‘MyNamespace.IClient’ in the method signature and is not in the known types collection. In order to serialize the parameter, add the type to the known types collection for the operation using ServiceKnownTypeAttribute.

    Of course you should not forget commenting this section before going into production or you might end up with some pretty big files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 83k
  • Answers 83k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer ReSharper has no such functionality built in, and I don't… May 11, 2026 at 4:46 pm
  • Editorial Team
    Editorial Team added an answer I am surprised no one had this need. Anyway after… May 11, 2026 at 4:46 pm
  • Editorial Team
    Editorial Team added an answer You're almost done... you have to actually insert it though...… May 11, 2026 at 4:46 pm

Related Questions

I am interested to learn about Eclipse RCP, I have got some basic knowledge,
I have to process a large byte array that is passed to my function.
I have been looking at using TDD and implementing proper testing (only just started
Using WCF in a RESTful way seems great. I’m a big fan of the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.