locked
400 bad request RRS feed

  • Question

  • I added a CKS tools WCF service to a new sharepoint project on my vm and deployed it. I made it a REST service but I am unable to access it by the url

    http://<servername>:portno/_vti_bin/<project name>/service name.svc/AddTags

    I get the error HTTP 400 bad request

    ----------

     [ServiceContract]
        public interface IServices
        {
            [OperationContract]
             [WebGet(ResponseFormat = WebMessageFormat.Json,RequestFormat=WebMessageFormat.Json,UriTemplate="/AddTags")]
            string AddTags();
        }

    ----------------------

     public string AddTags()
            {
                return "Hello World from WCF and SharePoint 2010";
            }

    I am to see the service details by adding "mex" at the end of the url


    • Edited by sanjuv Sunday, May 6, 2012 1:32 PM
    Sunday, May 6, 2012 1:32 PM

Answers

  • If you take the WCF template from CKS Dev and convert it to REST, you need to switch out the Factory in the *.svc file.

    It should be:

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

    Instead of WCF

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

    Have a browse through some of the materials here:

    http://johnliu.net/rest

    In general, you do not need to fiddle around with your web.config file or service bindings.  The ServiceHostFactory fixes those for you.


    jliu - http://johnliu.net - http://sharepointgurus.net


    • Edited by John Liu Tuesday, May 8, 2012 12:07 PM
    • Marked as answer by sanjuv Thursday, May 10, 2012 1:25 AM
    Tuesday, May 8, 2012 12:06 PM

All replies

  • Unfortunately (400) Bad Request is a very generic error and it happens if anything goes wrong :)

    What you pasted looks OK enough, but your binding settings may be off.

    You should turn Tracing on to get the real error, see: http://msdn.microsoft.com/en-us/library/ms733025.aspx

    I do this by deploying a web.config in the <project name> folder so I don't affect anything else.

    Hope this helps!


    Independant SharePoint Consultant. Feel free to contact me. Blog: http://www.sharepoint.bg/radi Twitter: @RadiAtanassov

    Sunday, May 6, 2012 3:54 PM
  • If you take the WCF template from CKS Dev and convert it to REST, you need to switch out the Factory in the *.svc file.

    It should be:

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

    Instead of WCF

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

    Have a browse through some of the materials here:

    http://johnliu.net/rest

    In general, you do not need to fiddle around with your web.config file or service bindings.  The ServiceHostFactory fixes those for you.


    jliu - http://johnliu.net - http://sharepointgurus.net


    • Edited by John Liu Tuesday, May 8, 2012 12:07 PM
    • Marked as answer by sanjuv Thursday, May 10, 2012 1:25 AM
    Tuesday, May 8, 2012 12:06 PM
  • Thanks a lot John for the reply. That solved my problem
    Thursday, May 10, 2012 1:25 AM