开发者

WCF "Method Not Allowed" in Visual Studio integrated webserver

I have two web projects in Visual Studio 2008 SP1, One hosting a WCF service and another that I am using to consume the WCF service. The service in question exposes a webHttpBinding endpoint and take JSON as input and returns JSON.

I have used Jquery ajax to consume the service from the client web app like so:

$(document).ready(function () {
    var data = '{"myobject":{"Business":"PIZZA"}}';
    $.ajax({
        type: "POST",
        contentType: "application/json",
        data: data,
        dataType: 'json',
        url: "http://localhost:1212/JobInfo.svc/ReturnThisString",
        error:
            function(XMLHttpRequest, textStatus, errorThrown) {
                alert("Error");
            },
        success: function(data) {
            alert("BoolValue: " + data.GetDataUsingDataContractResult.BoolValue);
            alert("StringValue: " + data.GetDataUsingDataContractResult.StringValue);
        }
    });

});

And I get the following error in the Firebug HTML request:

http://localhost:1212/JobInfo.svc/ReturnThisString 405 Method Not Allowed

But if run the exact same file in the web project that is hosting the project i开发者_运维问答t works fine.

The hosting project is running on set port localhost:1212 and the client on localhost:RANDOM_PORT. As the localhost is the same I would imagine its not a Cross Domain issue? Or does the port part count also?

The server contract is as follows:

[OperationContract]
[WebInvoke(Method="POST",UriTemplate="ReturnThisString", 
        BodyStyle=WebMessageBodyStyle.Wrapped, 
        RequestFormat=WebMessageFormat.Json, 
        ResponseFormat=WebMessageFormat.Json)]
EventListArgs ReturnThisString(EventListArgs myobject);

[Serializable]
[DataContract]
public class EventListArgs {

    [DataMember( IsRequired = false)]
    public string Business;

    [DataMember( IsRequired = false)]
    public string Feeder;

}

And the implemented code is:

public EventListArgs ReturnThisString(EventListArgs myobject)
{
    return myobject;
}

This was added as a simple method to prove I had not just done something silly. What I like to call a sanity check. Its a simple function that takes a complex(of type other then string) JSON object as a parameter and returns a complex JSON object.

WCF "Method Not Allowed" in Visual Studio integrated webserver

As you can see above I have two web project that use the Visual Studio Built in web server (local IIS install not possible). The above configuration does not work but if you can see I have also got the Darkside test page in the server host which is an exact copy from the client and this work with no problems at all.


Try using IIS Express It's got the same features as a full blown IIS and requires no install. A simple command line is all you need to start it up. It should get rid of the Casini related errors you were getting.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜