Solved

.net wcf web service 400 bad request

Posted on 2011-09-09
7
2,442 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now