我在Visual Studio 2008 SP1中有两个Web项目,一个托管WCF服务,另一个用于使用WCF服务。有问题的服务公开webHttpBinding端点并将JSON作为输入并返回JSON。Visual Studio集成web服务器中的WCF“方法不允许”
我已经使用jQuery的AJAX为使用来自客户端的Web应用程序,像这样的服务:
$(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);
}
});
});
而且我得到了Firebug的HTML请求以下错误:
http://localhost:1212/JobInfo.svc/ReturnThisString 405 Method Not Allowed
但如果运行在承载项目的Web项目中完全相同的文件工作正常。
托管项目在设置端口localhost:1212上运行,客户端在localhost上运行:RANDOM_PORT。由于本地主机是相同的,我会想象它不是跨域问题?还是端口部分也算?
服务器合同如下:
[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;
}
而实现的代码是:
public EventListArgs ReturnThisString(EventListArgs myobject)
{
return myobject;
}
此加入作为一个简单的方法来证明我没有刚刚做一些愚蠢的。我喜欢称之为健康检查。它是一个简单的函数,它接受一个复杂的(其他类型的字符串)JSON对象作为参数并返回一个复杂的JSON对象。
正如你可以在上面看到我有使用Visual Studio内置的Web服务器的两个网络项目(本地IIS安装是不可能的)。上面的配置不起作用,但是如果你能看到我也在服务器主机中获得了Darkside测试页面,这是来自客户端的精确副本,并且这完全没有问题。
好吧,但我不知道为什么它的工作原理,然后如果我从内置的卡西尼在同一个网络中运行它:-(所以当我运行它在托管SVC文件的同一网络上时,它工作正常 – Boden 2011-03-10 07:00:05
请问您服务实际上期望一个http POST或GET吗?你是否使用html
你从哪里运行服务?Casini服务器,IIS或其他什么?还有,当你使用像fiddler这样的工具发送请求时会发生什么呢?还要确保你实际处理POST方法, mimetype是正确的 – Polity 2011-03-10 16:22:07