Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
=============
C#
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;
        }
}

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


In calling.html page
====================
JavaScript
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
           });
       }
Posted
Comments
ZurdoDev 6-May-13 10:31am    
Where is the error occurring?

1 solution

The JSON version doesn't work because it's a cross-origin call (see: Same Origin Policy: http://en.wikipedia.org/wiki/Same_origin_policy[^]). Does the Google URL shortener have a JSON-P API? It has to explicitly support it. (Also, JSON-P can't be POST; by its nature it's a GET.)

Update: Looks like they don't support it yet, but there's an open enhancement request.
https://code.google.com/p/yourls/issues/detail?id=744[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900