2013-03-30 49 views
0

最近我已經開始在我的IOS中使用.NET的REST Webservice。 下列方式我已經創建了Web服務在我的.NET如何從IOS中調用Rest的Web服務?

Service1.cs文件

using System; 
using System.ServiceModel.Web; 

namespace WcfJsonRestService 
{ 
    public class Service1 : IService1 
    { 
     [WebInvoke(Method = "GET", 
        ResponseFormat = WebMessageFormat.Json, 
        UriTemplate = "data/{id}")] 
     public Person GetData(string id) 
     { 
      // lookup person with the requested id 
      return new Person() 
         { 
          Id = Convert.ToInt32(id), 
          Name = "Leo Messi" 
         }; 
     } 
    } 

    public class Person 
    { 
     public int Id { get; set; } 
     public string Name { get; set; } 
    } 
} 

我用Google搜索的東西,但它非常複雜的理解,因爲我從來沒有到過Web服務概念的iOS。 .so可以任何人請讓我指導如何以及在哪裏我可以調用這個Web服務,只需在Xcode 4.5的iOS設備標籤(IPAd)上顯示返回字符串。只需一個我想構建的演示應用

+0

REST風格的Web服務非常好,因爲它是如何訪問語言不可知的。 Google「如何在語言x中發出HTTP-GET」。將GET發送到正確的URL將返回一個包含您需要解析的數據的json字符串。然後查看「如何解析語言x中的JSON」。 – Despertar

+0

好的...... –

回答

3

你已經有了WCF JSON端點,現在你需要使用你的IOS應用程序中該端點產生的JSON。 Here is a tutorial關於如何做到這一點。