首先,我在我的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>