我创建了一个基于REST的WCF,其中ResponseFormat在Json中。我在网页上使用jquery ajax来调用这个wcf。一切正常。我在IIS 7.5中将wcf服务部署为端口8014中的单独网站。我部署了wcf调用客户端,该端口包含jcery ajax调用wcf作为端口8018中的单独网站。现在当我尝试访问基于Rest的wcf时我得到错误为“服务调用失败:0”。我使用VS2008 Framwork 3.5进行开发。
IService1:
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetProvinceREST/{Country}",
BodyStyle = WebMessageBodyStyle.Bare)]
string[] GetProvinceREST(string Country);
服务1:
public string[] GetProvinceREST(string Country)
{
string[] str = new string[3];
str[0]= "hi";
str[1]= "how";
str[2]= "are";
return str;
}
Jquery Ajax调用代码:
function CountryProvinceWCFREST() {debugger;
varType = "GET";
varUrl = "http://localhost:8014/Service1.svc/GetProvinceREST/" + $('#ddlCountry').val();
varContentType = "application/json; charset=utf-8";
varDataType = "json";
varProcessData = false;
CallService();
}
function CallService() {
$.ajax({
type: varType, //GET or POST or PUT or DELETE verb
url: varUrl, // Location of the service
data: varData, //Data sent to server
contentType: varContentType, // content type sent to server
dataType: varDataType, //Expected data format from server
processdata: varProcessData, //True or False
success: function(msg) {//On Successfull service call
ServiceSucceeded(msg);
},
error: ServiceFailed// When Service call fails
});
}
var ProvinceDDL = document.getElementById("ddlProvince");
for (j = ProvinceDDL.options.length - 1; j >= 0; j--) { ProvinceDDL.remove(j); }
var resultObject = null;
if (varType == "GET") { resultObject = result; }
for (i = 0; i < resultObject.length; i++) {
var opt = document.createElement("option"); opt.text = resultObject[i];
ProvinceDDL.options.add(opt)
}
<input type="button" value="Invoke" id="Button2" onclick="CountryProvinceWCFREST();" />
请帮帮我。