Search code examples
c#.netwcfwebhttpbinding

WebHttpBinding in .NET 4.0?


I'm unable to instantiate the WebHttpBinding class when referencing the System.ServiceModel and System.ServiceModel.Web libraries for .NET 4.0. I can instantiate the class when referencing the 3.5 libraries. The documentation says WebHttpBinding is supported in 4.0 so what am I doing wrong?

new ChannelFactory<INotesService>
(new WebHttpBinding(),
new EndpointAddress("http://localhost:3380/Service.svc"))

When I hit CTRL + . on WebHttpBinding it doesn't find the namespace for it.

http://msdn.microsoft.com/en-us/library/system.servicemodel.webhttpbinding.aspx


Solution

  • Yes, it is definitely in .NET 4, and its namespace was not changed or anything like that.

    Interestingly, it was moved from System.ServiceModel.Web.dll to System.ServiceModel.dll, with the type getting type-forwarded from System.ServcieModel.Web.dll perpetually. So, you should be able to transition any 3.5 projects to 4.0 and have it just work.

    So, your project should definitely work. If the target framework advice doesn't work, can you paste the error messages you get?