Solved

.net wcf web service 400 bad request

Posted on 2011-09-09
7
2,502 Views
Last Modified: 2012-05-12
I am stuck.  I am trying to make a wcf web service on my sharepont 2010 site.  I created my web service using a cksdev visual studio plugin that creates the file for you.  I had a more complex sample, but it wouldn't work, so I created a new one straight out of the box that returns a "hello world".

I am calling it from jQuery and keep getting a 400 bad request response that I can see in fiddler.

If I try an incorrect url, I get a file not found error, so I know that the web service exists.  I can't step into code and have no idea how to diagnose this.


my svc.cs file
    [BasicHttpBindingServiceMetadataExchangeEndpoint]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    public class WCFService1 : IWCFService1
    {
        // To test this service, use the Visual Studio WCF Test client
        // set the endpoint to http://<Your server name>/_vti_bin/Fmg.Extranet.ContextSelector.UI/WCFService1.svc/mex
        public string HelloWorld()
        {
            return "Hello World from WCF and SharePoint 2010";
        }
    }


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


My IWCFService1.cs file
    [ServiceContract]
    public interface IWCFService1
    {
        [OperationContract]
        string HelloWorld();
    }



My jQuery
                $.ajax({
                    url: "http://affiliatedfmonline/_vti_bin/Fmg.Extranet.ContextSelector.UI/WCFService1.svc/HelloWorld",
                    dataType: "json",
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(errorThrown);
                    },
                    success: function (data, textStatus, jqXHR) {
                        alert("success");
                        response($.map(data, function (item) {
                            return {
                                label: item.Name,
                                value: item.ID,
                                desc: item.Location
                            }
                        }));
                    }
                });

Open in new window

0
Comment
Question by:jackjohnson44
  • 4
  • 2
7 Comments
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 250 total points
ID: 36513871
remove line 35 because your send back a string
0
 

Author Comment

by:jackjohnson44
ID: 36513893
I just did and no luck.   That was actually from a more complicated sample.  I was at first returning a json object that was a seralized list collection and passed parameters in.  When I had difficulty, I removed the parameters and just tried to return a string.

Also, the issue is with the request, not the response.

Any other suggestions?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36513930
the domain/port/protocol are the same?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 7

Assisted Solution

by:gopaltayde
gopaltayde earned 250 total points
ID: 36515916
After the line
url: "http://affiliatedfmonline/_vti_bin/Fmg.Extranet.ContextSelector.UI/WCFService1.svc/HelloWorld",
                   
Add below line - contentType: "application/json; charset=utf-8",

0
 

Author Comment

by:jackjohnson44
ID: 36522649
leakim, I don't understand the question.  The url that I am using is correct.
gopal. I added that and am still getting the same error.
0
 

Accepted Solution

by:
jackjohnson44 earned 0 total points
ID: 36524061
I just figured out the issue.  I am using a visual studio plugin from codeplex, called cksdev.  When it generates a WCF service endpoint, it uses
Factory="Microsoft.SharePoint.Client.Services.MultipleBaseAddressBasicHttpBindingServiceHostFactory
This doesn't work, but this does
Factory="Microsoft.SharePoint.Client.Services.MultipleBaseAddressWebServiceHostFactory

Does anyone know the difference?
0
 

Author Closing Comment

by:jackjohnson44
ID: 36565428
My solution was correct
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question