我有一个返回自定义对象的 WCF 服务(这在浏览器中有效),但是当我从 Javascript 调用该服务时,我在 FF 中得到了无效标签错误。当我将它http://localhost/Service1.svc/MethodName/param1/param2
放入浏览器时,我得到了正确的信息,但它看起来与我将其转换为 JSONP 之前的 JSON 响应相同,即。我不确定响应是否有包装器。我正在使用的javascript如下:
function CallService() {
$.ajax({
cache:true,
type: varType, //GET or POST or PUT or DELETE verb
url: varUrl, // Location of the service
data: varData, //Data sent to server
crossDomain: true,
contentType: varContentType, // content type sent to server
dataType: varDataType, //Expected data format from server
processdata: varProcessData, //True or False
success: function (msg) {//On Successful service call
ServiceSucceeded(msg);
},
error: ServiceFailed// When Service call fails
});
function SetupTrainList(tiploc) {
try {
varType = "GET";
varUrl = "http://localhost/Service1.svc/MethodName/param1/param2";
varContentType = "application/javascript";
varDataType = "jsonp";
varProcessData = false;
CallService();
}
catch (e) {
console.log(e.toString());
}
}
世界足联:
<OperationContract()>
<WebInvoke(BodyStyle:=WebMessageBodyStyle.Bare,
Method:="GET",
RequestFormat:=WebMessageFormat.Json,
ResponseFormat:=WebMessageFormat.Json,
UriTemplate:="MethodName/{param1}/{param2}")>
Function MethodName(ByVal param1 As String, ByVal param2 As String) As ComplexType