Wcf – SVC in SharePoint Foundation 2010 Gives HTTP 400: Bad Request

sharepointsharepoint-2010wcf

A bit of background. I've worked with ASMX and PageMethods, but no WCF so far. I'm developing on Win 7 Pro with Windows Communication Foundation HTTP Activation installed as well as Windows Communication Foundation HTTP Non-Activation installed. I'm also deploying to SharePoint Foundation 2010 that is also running on my machine.

I'm developing custom web service for SharePoint that is accessing non-SharePoint data. I found several articles on creating a WCF service in SharePoint. I followed the instructions in this one, http://answers.oreilly.com/topic/1404-how-to-customize-wcf-services-in-sharepoint-2010

I'm able to load the MEX, e.g. http://mySite.com/Services/MyService.svc/MEX, but if I go to http://mySite.com/Services/MyService.svc I get an HTTP 400 Bad Request.

Looking in the Event Viewer logs, there is nothing related to this error. IIS Logs show only the GETs to the service.

I'm assuming it's either not properly deployed or there's some permissions issue.

Best Answer

I got the same issue as you described when developing a REST service. The solution was to change the Factory to use to MultipleBaseAddressWebServiceHostFactory used for REST services instead of MultipleBaseAddressBasicHttpBindingServiceHostFactory that is used for SOAP services.

For example in the .svc file:

<%@ ServiceHost Language="C#" Debug="true"
Service="MyProject.WCFService1, $SharePoint.Project.AssemblyFullName$"  
CodeBehind="WCFService1.svc.cs"
Factory="Microsoft.SharePoint.Client.Services.MultipleBaseAddressWebServiceHostFactory, Microsoft.SharePoint.Client.ServerRuntime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

Here is a discription of the different types of factories you can use, provided by Andy Kinnear:

  • MultipleBaseAddressBasicHttpBindingServiceHostFactory

    Use for SOAP services. Basic HTTP binding must be used, which creates endpoints for a service based on the basic HTTP binding.

  • MultipleBaseAddressWebServiceHostFactory

    Use for REST services. The service factory creates endpoints with web bindings.

  • MultipleBaseAddressDataServiceHostFactory

    Use for ADO.NET data services. A data service host factory can be used.

Related Topic