WCF JSONP启用服务 - 返回无效标签

时间:2012-08-14 10:57:57

标签: javascript wcf jsonp

我有一个返回自定义对象的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());
    }
}

WCF:

<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

0 个答案:

没有答案