Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WCF jQuery JSON
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 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;
        }
}
====================================
 

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
           });
       }
Posted 6-May-13 5:20am
Comments
ryanb31 at 6-May-13 10:31am
   
Where is the error occurring?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 325
1 DamithSL 265
2 CPallini 235
3 Sergey Alexandrovich Kryukov 229
4 Maciej Los 190
0 OriginalGriff 5,455
1 DamithSL 4,422
2 Maciej Los 3,860
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,010


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 8 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100