Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>At first glance there are three problems with your code:</p> <p>1: you should use the <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.serviceknowntypeattribute.aspx" rel="nofollow noreferrer">ServiceKnownTypeAttribute</a> to specify known types when exposing only base types in your operation contracts:</p> <pre><code>[ServiceContract(Namespace = "yyyWCF")] public interface IClientBroker { [OperationContract] [ServiceKnownType(typeof(Client))] [WebInvoke( Method="GET", BodyStyle=WebMessageBodyStyle.WrappedRequest, ResponseFormat=WebMessageFormat.Json)] IClient GetClientJson(int clientId); } </code></pre> <p>2: You should use <code>WebMessageBodyStyle.WrappedRequest</code> instead of <code>WebMessageBodyStyle.Wrapped</code> because the latter is not compatible with <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.activation.webscriptservicehostfactory.aspx" rel="nofollow noreferrer">WebScriptServiceHostFactory</a>.</p> <p>3: IMHO using Method="GET" would be more RESTful for a method called GetClientJson than Method="POST"</p> <p>Another advice I could give you when working with WCF services is to use <a href="http://msdn.microsoft.com/en-us/library/ms732023.aspx" rel="nofollow noreferrer">SvcTraceViewer.exe</a> 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:</p> <pre><code> &lt;system.diagnostics&gt; &lt;sources&gt; &lt;source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true"&gt; &lt;listeners&gt; &lt;add name="sdt" type="System.Diagnostics.XmlWriterTraceListener" initializeData= "WcfDetailTrace.e2e" /&gt; &lt;/listeners&gt; &lt;/source&gt; &lt;/sources&gt; &lt;/system.diagnostics&gt; </code></pre> <p>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:</p> <blockquote> <p>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.</p> </blockquote> <p>Of course you should not forget commenting this section before going into production or you might end up with some pretty big files.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload