1

首先,我在我的 asp.net 应用程序中使用了 WCF 服务,一切正常。但它在我的 phonegap 应用程序中不起作用。这是我的详细错误信息。(前两个是警告,最后一个是错误。) 警告 1:不支持 Viewport target-densitydpi。index.html:7 警告 2:资源解释为脚本,但使用 MIME 类型 text/html 传输:“http://:64514/Service1.svc?wsdl/MyFunction&callback=jQuery1900010203775251284242_1364550121569&Count1&_=1364550121570”。
错误 1:未捕获 SyntaxError:意外令牌 < Service1.svc:1

这是我的代码片段。我的 WCF 代码:

    [OperationContract]
    [WebInvoke(Method = "POST",
    BodyStyle = WebMessageBodyStyle.Wrapped,
    ResponseFormat = WebMessageFormat.Json)]
    string MyFunction(string value);

    public string MyFunction(string Count)
    {
        return "The Count you passed in is: " + Count.ToString();
    }

我的 HTML 代码:

    <script type="text/javascript">

    var counter = 0;
    var varType;
    var varUrl;
    var varData;
    var varContentType;
    var varDataType;
    var varProcessData;

    function CallMyService() {
    counter++;

    varType = "POST";
    varUrl = "http://<domain>:64514/Service1.svc?wsdl/MyFunction";
    varData = "Count" + counter;
    varContentType = "application/javascript; charset=utf-8";
    varDataType = "jsonp";
    varProcessData = true;

    CallWcfService();
    return true;
    }

    function CallWcfService() {
    $.ajax({
    type: varType,
    url: varUrl,
    data: varData,
    contentType: varContentType,
    dataType: varDataType,
    crossDomain: true,
    processdata: varProcessData,
    success: function (msg) {
    ServiceSucceeded(msg);
    },
    error: ServiceFailed
    });
    }

    function ServiceFailed(result) {
    Log('Service call failed: ' + result.status + '  ' + result.statusText);
    return 0;
    }

    function ServiceSucceeded(result) {
    resultObject = result.MyFunctionResult;
    Log("Success: " + resultObject);
    }

    function Log(msg) {
    $("#logdiv").append(msg + "<br />");
    }
    </script>

    </head>
    <body>
    <input id="Button1" type="button" value="Execute" onclick="CallMyService();" />

    <div id="logdiv"></div> 
    </body>

我的 WCF 网络配置文件:

    <services>
    <service behaviorConfiguration="Service.Service1Behavior" name="WcfService1.Service1">
    <endpoint address="" binding="wsHttpBinding" contract="WcfService1.IService1">
    <identity>
    <dns value="http://<domain>:64514/" />
    </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    </service>
    </services>
4

0 回答 0