本文介绍了WCF for Json / Jquery获取状态列表..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从WCF返回通用列表。但返回未知错误。任何人都可以帮我解决这个问题。


IService.cs中的


==============

[ServiceContract]

公共接口IServiceLP18

{

[OperationContract]

[WebInvoke(Method =POST) ,BodyStyle = WebMessageBodyStyle.Wrapped,ResponseFormat = WebMessageFormat.Json)]

List< lp18wcf.servicelp18.statecls> GetAllStates();

}


ServiceLP18中的


=========== ==

I am trying to return a generic list from a WCF. But return an "unknown" error. Can anyone help me out to solve this.

in IService.cs
==============
[ServiceContract]
public interface IServiceLP18
{
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
List<lp18wcf.servicelp18.statecls> GetAllStates();
}

in ServiceLP18
=============

public class ServiceLP18 : IServiceLP18
{
  public class StateCls
        {
            public string StateID;           
            public string StateName;
        }
        public List<StateCls> GetAllStates()
        {
            List<StateCls> StateList = new List<StateCls>();
            for (int i = 0; i < 10; i++)
            {
                StateCls tempRow = new StateCls();               
                tempRow.StateID = i.ToString();
                tempRow.StateName = "Sate " + i.ToString();
                StateList.Add(tempRow);
            }          
            return StateList;
        }
}



========================= ===========





在calling.html页面

== ==================


====================================


In calling.html page
====================

function CallGetStates() {
           $.ajax({
               Type : "POST",
               url: "http://localhost:50609/ServiceLP18.svc/GetAllStates", 
               data: "{}", 
               contentType: "application/json; charset=utf-8", 
               dataType: "jsonp", 
               processdata: true, 
               success: function (response) {
                   var statess = response.d;
                   $.each(statess, function (index, LpStates) {
                       alert(LpStates.StateName);
                   });                   
               },
               error: ServiceFailed// When Service call fails
           });
       }

推荐答案




这篇关于WCF for Json / Jquery获取状态列表..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 20:11