?
Solved

.net wcf web service 400 bad request

Posted on 2011-09-09
7
Medium Priority
?
2,579 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 1000 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Assisted Solution

by:gopaltayde
gopaltayde earned 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

764 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