WCF: NotSupportedException: The SSL settings for the service ‘SslRequireCert’ does not match those of the IIS ‘Ssl’.

When you are using WCF with client certificate over SSL in web hosted case, you might hit an exception like the following: [NotSupportedException: The SSL settings for the service ‘SslRequireCert’ does not match those of the IIS ‘Ssl’.] System.ServiceModel.Activation.HostedAspNetEnvironment.ValidateHttpsSettings(String virtualPath, Nullable`1& requireClientCertificate) +117347 System.ServiceModel.Channels.HttpsChannelListener.ApplyHostedContext(String virtualPath, Boolean isMetadataListener) +97 System.ServiceModel.Activation.HostedAspNetEnvironment.ApplyHostedContext(TransportChannelListener listener, BindingContext context) +84 System.ServiceModel.Channels.HttpsTransportBindingElement.BuildChannelListener(BindingContext context)…

1

Learning SignalR: Unable to get property ‘client’ of undefined or null reference

One of the most common exceptions you will hit when you first started with a SignalR chat program could look like the following: Unhandled exception at line 78, column 13 in http://localhost:53632/home/chat 0x800a138f – JavaScript runtime error: Unable to get property ‘client’ of undefined or null reference Why? This is mostly like caused by the…

5

How to customize parameter binding

Web API provides some great out of box experience with parameter binding. It also provides some powerful extensibility points to allow you customize that binding process. For example, you can bind multiple parameters from uri. However, it can only bind one parameter from request content by default. If you try to mark multiple parameters with [FromBody] attribute, you will get an…

2

How to retrieve all the filters that applies to one particular action in Web API

Sometimes you want to retrieve all the filters that one action supports, and you can do that via the following code snippet. Hope this helps. Code Snippet          Collection<FilterInfo> filterInfoCollection = action.GetFilterPipeline(); // here action is action descriptor            foreach (FilterInfo filterInfo in filterInfoCollection)          {              if (filterInfo.Instance is MyQueryableAttribute)              {                   supportQueryable = true;                   break;…

0

How to access the Client’s IP address in Web API

For web hosted, you can access your client address via the following: Code Snippet             string clientAddress = HttpContext.Current.Request.UserHostAddress; For self hosted, you can access your client address via the following: Code Snippet             object property;             Request.Properties.TryGetValue(typeof(RemoteEndpointMessageProperty).FullName, out property);             RemoteEndpointMessageProperty remoteProperty = property as RemoteEndpointMessageProperty; Hope this helps. 

0

How to write a custom parameter binding to construct an object either from body or from Uri’s query

Mike has wrote this really good blog on writing a custom HttpParameterBinding at http://blogs.msdn.com/b/jmstall/archive/2012/05/11/webapi-parameter-binding-under-the-hood.aspx My blog just want to add a little bit complex example where you might want to have an action which looks like the following: Code Snippet public class HomeController : ApiController {     [HttpGet]     [HttpPost]     public HttpResponseMessage BindCustomComplexTypeFromUriOrBody(TestItem item)     {         return new…

1

How to access ClientCertificate in a host agnostic manner

 When you choose to use Client Certificate as your client credential over SSL, you want to retrieve the x509 Certificate on the server side to do authorization. It is very simple with the latest Web API bits. If you have access to the request message anywhere in the pipeline, such as message handler, action filter…

3

How to support multiple authentication in self host

Since we build web api self host story on top of WCF HttpTransportBindingElement, the multiple authentication is not support on WCF for 4.0. Here is the exception you will get if you tried to set the authentication scheme on httptransport binding element. “System.ArgumentException: The ‘Negotiate, Anonymous’ authentication scheme has been specified on the HTTP factory….

0

How to access HTTPContext from within your Web API action

Within a Web API action, you can easily access the HttpContext via the HttpContext.Current thread static. Alternatively, you can also retrieve the context from one of the properties in the Request message. Code Snippet HttpContext context; Request.Properties.TryGetValue<HttpContext>(“MS_HttpContext”, out context); Hope this helps.

0