PhoneGap Wcf服务

时间:2013-09-07 13:19:06

标签: wcf cordova

我有一个来自移动平台的wcf服务。当我从移动设备中的浏览器调用wcf时,它可以工作。然后我将我的html转换为使用手机的应用程序。但这一次,我无法调用wcf服务。有任何想法吗? 这是我的HTML;

<title>Mobilizm</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="css/Mobilizm.css" rel="stylesheet" />
    <link href="css/jquery.mobile.structure-1.3.2.min.css" rel="stylesheet" />

     <script src="js/JSON.js"></script>
    <script src="js/jquery.js"></script>
    <script src="js/jquery.mobile-1.3.2.js"></script>  
    <script>
        $(document).on("pageinit", function (event) {

            $('#save').click(function () {
                debugger;
                var typesArray = new Array();
                var myType = new Object();
                myType.FirstName = $("#name").val();
                myType.LastName = $("#surname").val();
                myType.EMailAddress1 = $("#email").val();
                myType.MobilePhone = $("#cellphone").val();
                typesArray.push(myType);

                $.support.cors = true;
                $.getJSON("http://xxxxx/Mobile/MobilizmService.svc/CreateCustomer?callback=?", { customers: JSON.stringify(typesArray), origin: 167440003, status: 167440001 })
                .done(function (json) {
                    alert("ok");
                })
                .fail(function (jqxhr, textStatus, error) {
                    alert("false");
                });

    </script>

</head>
<body>
    <div data-role="page">
        <div data-theme="d" data-role="header">
            <h3>Yeni Kullanıcıgg</h3>
        </div>
        <div  data-role="content">

            <div data-role="fieldcontain">
                <label for="name">Ad:</label>
                <input type="text" name="name" id="name" value="" data-mini="true" />
            </div>

            <div data-role="fieldcontain">
                <label for="surname">Soyadı:</label>
                <input type="text" name="surname" id="surname" value="" data-mini="true" />
            </div>
            <div data-role="fieldcontain">
                <label for="email">E-Posta:</label>
                <input type="text" name="email" id="email" value="" data-mini="true" />
            </div>
            <div data-role="fieldcontain">
                <label for="cellphone">Cep Telefonu:</label>
                <input type="text" name="cellphone" id="cellphone" value="" data-mini="true" />
            </div>

            <input data-theme="d" type="button" value="Kaydet" id="save" />

        </div>
        <div data-theme="d" data-role="footer">
            <h3>Yeni Kullanıcı</h3>
        </div>
    </div>

2 个答案:

答案 0 :(得分:1)

经过几个小时的搜索,ı解决了问题。您必须将此标记添加到config.xml文件中。您的来源是您托管网络服务的地方。

<access origin="xxx" subdomains="true" />

答案 1 :(得分:0)

试试我的代码:

var serviceUrl = 'http://' + _SERVER_ADDRESS + '/RestService.svc/' + method;
var jsonCallbackMethod = 'spycallback493285721';

$.ajax({
    type : "GET",
    url : serviceUrl,
    jsonpCallback : jsonCallbackMethod,
    data : params,
    dataType : 'jsonp',
    timeout : 11*1000 // Necessary in order to detect not found(404) error
})