3
votes

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.

5
My 400 with a SharePoint Web Site (not a SVC) was an incorrect binding in IIS.PeterX

5 Answers

7
votes

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.

0
votes

Do you have httpGetEnabled in the .config file (or equivalent code)?

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <serviceMetadata httpGetEnabled="true"/>
      </behavior>
    </behaviors>
  </serviceBehaviors>
</system.serviceModel>

reference: http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicemetadatabehavior.httpgetenabled.aspx

0
votes

As far as I can tell this is not a problem (getting HTTP 400 when you visit the .svc but not when visiting /mex).
I am having the same issue and my SharePoint WCF services are working properly. Try to call your service from a simple console application and it will work, e.g.
SomeServiceClient proxy = new SomeServiceClient(new BasicHttpBinding(), new EndpointAddress("http://server/_vti_bin/YourService.svc"));

0
votes

Just for advice i recommend you use CKSDevs Tools it have templates for many standart sharepoint elements including WCF service.

And also i don't see a problem here, you say that endpoint works correct thats good. What you expected to see at the /MyService.svc? You simple not pass any query to service so it don't know what to do and throws 400.

0
votes

Try looking at the Service request in Fiddler. Also try to see if any of the below URL's are working for you :

http://server/_vti_bin/MyService.svc/negotiate

http://server/_vti_bin/MyService.svc/ntlm

http://server/_vti_bin/MyService.svc/anonymous