Posts

Showing posts with the label WCF

400 Bad Request when trying to add a Web Reference

This morning, I had a hard time adding a Web Reference in my CF application pointing to a WCF service. I checked the service several times, re-built it several times as well, but each time I got a HTTP 400 Bad Request when clicking the "Go" button of the Add Web Reference wizard. And then, I copied/pasted the URL one more time deleting the mex part at the end but leaving the ending slash. And it worked. I had removed the ending slash and thus caused this annoying behavior. I lost 5 minutes over such a stupid problem... Hope it will help one of you someday :)

Accessing a WCF service using Compact Framework

A few constraints when connecting to a WCF service from a Compact Framework application : The binding must be set to basicHttpBinding, CF does not know what to do with a wsHttpBinding. The XmlSerializerFormat attribute must be set on the service contract, the default WCF serialization is not suitable for the CF. It would throw an exception when deserializing. Make sure you configure your endpoints correctly, "localhost" is not accessible from the mobile device (emulated or not), you can use ppp_peer as the hostname in the CF WCF proxy (a lot of CFs, I know). Happy CF coding :)

Handling exceptions the right way in WCF (part 2)

In my previous post I talked about FaultExceptions and how they are transmitted from the server to the client. First, let's have a look at the sample service contract : [ServiceContract] public interface ITimeService { [OperationContract] [FaultContract(typeof(TimeExceptionDetails))] DateTime GetTime(); } The service implementation : public class TimeService : ITimeService { #region ITimeService Members public DateTime GetTime() { return DateTime.Now; } #endregion } And the Fault details class : public class TimeExceptionDetails { public static readonly TimeExceptionDetails Default = new TimeExceptionDetails(); [DataMember] public String Message { get; private set; } public TimeExceptionDetails() { this.Message = "There is a problem in the spacetime continuum, Marty"; } public TimeExceptionDetails(String message) { this.Message = message; } } Now we'll learn how to ease the process of creating FaultExceptions by using the IE...

Handling exceptions the right way in WCF (part 1)

Control over exceptions is very important in WCF because exceptions can contain a lot of information about the internals of your service potentially leading to security issues. WCF allows to define not only data, service or message contracts but also fault contracts. Fault contracts are used to materialize potential exceptions in the metadata of your service. To do that, you just have to declare on your service contract which exception might be raised by a specific method. Here is a simple service contract : [ServiceContract] public interface IService1 { [OperationContract] [FaultContract(typeof(SomeFault))] void DoSomething(); } Here, we are telling the WCF runtime to expose a fault contract in the service metadata. The object containing the fault detail is named SomeFault. Here is the definition of the SomeFault class : [DataContract] public class SomeFault { [DataMember] public String SomeInfo { get; set; } } As you see, SomeFault is a data contract. Its use is only t...