我不记得我是如何得到这个错误和什么时候。但是,正如很多有这个问题的人,我想要发布我所做的。
WCF - IService
[OperationContract]
[WebGet(BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "SetJSON?data={data}")]
string SetJSON(string data);
WCF - 服务
[AspNetCompatibilityRequirements(RequirementsMode =
AspNetCompatibilityRequirementsMode.Allowed)]
public class Service : IService
{
public string SetJSON(string data)
{
return data;
}
}
WCF - web.config中
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP"
crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
....
<services>
<service name="RnDService.Service">
<endpoint address="" behaviorConfiguration="webHttpBehavior"
binding="webHttpBinding"
bindingConfiguration="webHttpBindingWithJsonP"
contract="RnDService.IService" />
</service>
</services>
jQuery的通话
$.ajax({
type: "GET",
url: "http://localhost:81/Test/Service.svc/SetJSON?data=" + "{ \"dl\":" + datalist + " }",
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
success: function (data) {
alert(data.toString());
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
debugger;
alert("Error Occured!");
}
});
不是100%确定什么解决了我的问题。无论如何,这将有助于某人。 :)
这是因为该端口是不同的我想 – 2012-03-22 04:51:36