带有JSON未定义错误的WCF [英] WCF with JSON Undefined Error

查看:79
本文介绍了带有JSON未定义错误的WCF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我在使用JSON的WCF问题时没有显示任何内容....显示未定义



JSON:



Hi i am in problem with WCF with JSON it show nothing ....show undefined

JSON :

function CallMyService() {
          $.ajax({
              type: "POST",
              url: "http://localhost:82/BookingRequest.svc/AutoSuggestBookPanel?prefixText=Australia&ReturnType=json",
              contentType: "application/json;charset-uf8", // content type sent to server
              dataType: "json", //Expected data format from server
              success: function (msg) {
                  alert(msg);
              },
              error: function (response, textStatus, errorThrown) {

                  alert(response.responseText);
                  alert(textStatus.responseText);
                  alert(errorThrown);
              }
          });
      }





.cs文件



.cs File

[OperationContract]
      [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
          UriTemplate = "/AutoSuggestBookPanel?prefixText={prefixText}&ReturnType={ReturnType}")]
      String AutoSuggestBookPanel(String prefixText, String ReturnType);







请给我帮助......




please give me help......

推荐答案

.ajax({
type: POST
url: http:// localhost:82 / BookingRequest.svc / AutoSuggestBookPanel?prefixText = Australia& ReturnType = json
contentType: application / json; charset-uf8 // content发送到服务器的类型
dataType: json // 来自服务器的预期数据格式
成功:函数(msg){
alert(msg) ;
},
错误:function(response,textStatus,errorThrown){

alert(response.responseText);
alert(textStatus.responseText);
alert(errorThrown);
}
});
}
.ajax({ type: "POST", url: "http://localhost:82/BookingRequest.svc/AutoSuggestBookPanel?prefixText=Australia&ReturnType=json", contentType: "application/json;charset-uf8", // content type sent to server dataType: "json", //Expected data format from server success: function (msg) { alert(msg); }, error: function (response, textStatus, errorThrown) { alert(response.responseText); alert(textStatus.responseText); alert(errorThrown); } }); }





.cs文件



.cs File

[OperationContract]
      [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
          UriTemplate = "/AutoSuggestBookPanel?prefixText={prefixText}&ReturnType={ReturnType}")]
      String AutoSuggestBookPanel(String prefixText, String ReturnType);







请给我帮助......




please give me help......


OP的评论:



OP's Comment:

引用:

我已在我的本地托管此服务并且工作正常。当我在浏览器中运行此服务时,通过放置查询ystring值硬编码然后它给我回复但是当我从我的跨域网页调用此函数时它给我错误...

i have hosted this service in my local and its working properly.when i run this service in my browser by putting querystring value hard coded then it is giving me reply but when i call this function from my cross domain web page it gives me error...







根据您的评论,您无法以这种方式测试您的WCF服务。如果您需要从跨域测试它,那么您必须在公共IIS服务器上托管您的服务。它将无法与localhost一起使用你试过的方式(即url:http:// localhost:82 / BookingRequest.svc / AutoSuggestBookPanel?prefixText = Australia& ReturnType = json,)。



所以在公共场合托管你的服务IIS服务器,然后通过在上面的js方法上替换该主机URL来检查。




According to your comments you cannot test your WCF service that way.If you need to test it from cross domain then you have to host your service on Public IIS server.It won't work with the localhost the way you tried (i.e. url: "http://localhost:82/BookingRequest.svc/AutoSuggestBookPanel?prefixText=Australia&ReturnType=json", ).

So host your service on public IIS server and check after that by replacing that host url on above js method.


这篇关于带有JSON未定义错误的WCF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆