Do you use enum types in your WCF web services?

The reason people recommend to avoid enums in webservices is because they create subtle backwards compatible problems. The same applies to regular enums but in web services the problem is even more clear specially in .NET-generated proxies (see below). If the enumerate is input only you have no issues. If the enumerate can be an … Read more

Timeouts WCF Services

Client side: SendTimeout is used to initialize the OperationTimeout, which governs the whole interaction for sending a message (including receiving a reply message in a request-reply case). This timeout also applies when sending reply messages from a CallbackContract method. OpenTimeout and CloseTimeout are used when opening and closing channels (when no explicit timeout value is … Read more

Obtaining client IP address in WCF 3.0

This doesn’t help you in 3.0, but I can just see people finding this question and being frustrated because they are trying to get the client IP address in 3.5. So, here’s some code which should work: using System.ServiceModel; using System.ServiceModel.Channels; OperationContext context = OperationContext.Current; MessageProperties prop = context.IncomingMessageProperties; RemoteEndpointMessageProperty endpoint = prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; … Read more

ContractFilter mismatch at the EndpointDispatcher exception

A “ContractFilter mismatch at the EndpointDispatcher” means the receiver could not process the message because it did not match any of the contracts the receiver has configured for the endpoint which received the message. This can be because: You have different contracts between client and sender. You’re using a different binding between client and sender. … Read more

Where to store data for current WCF call? Is ThreadStatic safe?

There’s a blog post which suggests implementing an IExtension<T>. You may also take a look at this discussion. Here’s a suggested implementation: public class WcfOperationContext : IExtension<OperationContext> { private readonly IDictionary<string, object> items; private WcfOperationContext() { items = new Dictionary<string, object>(); } public IDictionary<string, object> Items { get { return items; } } public static … Read more

Returning raw json (string) in wcf

Currently your web method return a String together with ResponseFormat = WebMessageFormat.Json. It follow to the JSON encoding of the string. Corresponds to www.json.org all double quotes in the string will be escaped using backslash. So you have currently double JSON encoding. The easiest way to return any kind of data is to change the … Read more