Solved

.net wcf web service 400 bad request

Posted on 2011-09-09
7
2,519 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 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
Technology Partners: 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 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 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