2012-10-12 79 views
1

我試圖通過使用MonoTouch的一個HttpWebRequest對象獲取JSON數據。它的工作原理在IPhone模擬器罰款,我得到JSON回來。但是當我在設備上運行應用程序時,當調用Web服務時,我總是返回XML而不是JSON。web服務中的MonoTouch返回XML而不是JSON

是否有任何特定的配置參數,我將不得不設置結果作爲JSON,運行時從iPhone?我在IPhone 5,iOS 6中運行這個..

這裏是我的代碼..

var request = HttpWebRequest.Create(String.Format (@"{0}/GetActiveProductCountAfterID/filter?minID={1}",baseUrl, lastProductNumberInDatabase)); 
Logger.Debug("Request URL is: " + request.RequestUri); 
request.ContentType = @"application/json"; 
request.Method = "GET"; 
try{ 
    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) 
    { 
     if (response.StatusCode != HttpStatusCode.OK) 
      Console.Out.WriteLine("Error fetching data. Server returned status code: {0}", response.StatusCode); 
     using (StreamReader reader = new StreamReader(response.GetResponseStream())) 
     { 
      string content = reader.ReadToEnd(); 
........ 

當我在模擬器中運行,我得到的內容作爲integer..for例如:3456

但是,當我從IPhone運行它,我得到

<int xmlns="http://schemas.microsoft.com/2003/10/Serialization/">3456</int> 
+0

如果你可以分享(私下),網址爲您服務,請從模擬器和設備都填補http://bugzilla.xamarin.com一個錯誤報告如果是內部則網絡跟蹤(例如使用Wireshark完成)(需要做服務器端)可以幫助我們來看看什麼地方出了錯。 – poupou

回答

0

通過設置服務器端Web服務有JSON作爲默認的Web服務解決它。對於那些你誰可能會遇到同樣的問題,這裏是我必須做的有JSON作爲默認的格式(基於.NET WCF的web.config文件服務器)

<system.serviceModel> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 
<standardEndpoints> 
    <webHttpEndpoint> 
    <standardEndpoint name="" helpEnabled="true" defaultOutgoingResponseFormat="Json" /> 
    </webHttpEndpoint> 
</standardEndpoints> 

相關問題