I’m new to WCF Web Service and don’t know a lot how to debug web services…
Following examples, I created a Web service which has the interface like this:
public interface IMyService
{
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
List<MyClass> GetData(string param);
}
and the implementation which returns a list of MyClass.
After the deployment, I called the service in Fiddler like
http://localhost/MyService.svc/GetData?keyword=blabla
It returns:
HTTP/1.1 401 Unauthorized
Server: Microsoft-IIS/7.5
SPRequestGuid: blabla
WWW-Authenticate: blabla
X-Powered-By: ASP.NET
MicrosoftSharePointTeamServices: 14.0.0.6114
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET, OPTIONS
Date: Mon, 12 Nov 2012 17:24:08 GMT
Content-Length: 0
and if I just write in the composer:
http://localhost/MyService.svc/GetData
without the param, it returns un empty json with status 200.
When I try the first request in Chrome, it demanded consecutively my username and password to the server, but entering them didn’t help me get out of the loop(of demanding username and password).
Has anyone encountered problem like this?
Or could you give any suggestion on the debugging?
WCF Services don’t typically allow GET access out of the box. To plagarise my own answer (here: https://stackoverflow.com/a/13229373/1014822) you need a configuration section in your web.config that looks something like this:
You may not need the cross domain elements, but you will at least need the endpoint behavior that permits
<webHttp />and the service behavior that allows<serviceMetadata httpGetEnabled="true" />. You can’t then have a configuration-less service – you need the<service/>element in order to be able to bind those behaviors. You will need to complete the<service/>element with the name of your service, and the interface name of your contract (e.g.IMyService)If you are only testing via GET because it’s easier to do, but will use POST (or some protocol other than http) in your actual app, then you might consider using the WCF test client for debugging, instead of the browser and/or fiddler. Details of the client here: http://msdn.microsoft.com/en-us/library/bb552364.aspx