2011-01-30 15 views
5

मैंने सब कुछ करने की कोशिश की है और मुझे पता नहीं चल रहा है कि यह त्रुटि क्यों होती है।बिज़ारे HttpWebResponse त्रुटि: सर्वरप्रोटोकॉल उल्लंघन

पृष्ठभूमि: मैं एक iPad आवेदन, MonoTouch में लिखा है और मैं एक धागा है कि पृष्ठभूमि में चलता है, और प्रत्येक 15 सेकंड मैं सर्वर के साथ डेटा सिंक। यह धागे के पहले कुछ पुनरावृत्तियों को काम करता है, लेकिन अंततः मुझे निम्नलिखित स्टैक ट्रेस मिलता है।

An exception occured: System.Net.WebException: Error getting response stream (ReadDone4): ServerProtocolViolation ---> System.FormatException: Input string was not in the correct format 
    at System.UInt32.Parse (System.String s) [0x00010] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/UInt32.cs:405 
    at System.Net.WebConnection.GetResponse (System.Byte[] buffer, Int32 max) [0x000ba] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/WebConnection.cs:565 
    at System.Net.WebConnection.ReadDone (IAsyncResult result) [0x00095] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/WebConnection.cs:446 
    --- End of inner exception stack trace --- 
    at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x0005e] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:819 
    at System.Net.HttpWebRequest.GetResponse() [0x0000e] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:827 
    at SyncService.REST.RestClient.Execute[IEnumerable`1] (SyncService.REST.RestRequest request) [0x00079] in /Users/Chris/Compass/SyncService/REST/RestClient.cs:42 

मैं डिफ़ॉल्ट विन्यास के साथ एक IIS वेबसर्वर बात कर रहा हूँ।

public RestResponse<T> Execute<T>(RestRequest request){ 
    var restResponse = new RestResponse<T>(); 
    var serializer = new JavaScriptSerializer(); 
    var urlPath = _baseUrl + "/" + request.Resource; 
    var httpRequest = (HttpWebRequest)HttpWebRequest.Create(new Uri(urlPath)); 

    httpRequest.Headers = request.Headers; 
    Authenticator.Authenticate(httpRequest); 

    httpRequest.Method = request.Method.ToString(); 
    if (request.Method == Method.POST) 
     SetPostData(httpRequest, request); 

    HttpWebResponse httpResponse = null; 
    try{ 
     httpResponse = (HttpWebResponse) httpRequest.GetResponse(); 
     var reader = new StreamReader(httpResponse.GetResponseStream()); 
     var responseString = reader.ReadToEnd(); 
     reader.Close(); 
     restResponse.StatusCode = httpResponse.StatusCode; 
     restResponse.Headers = httpResponse.Headers; 
     restResponse.Data = serializer.Deserialize<T>(responseString); 
     restResponse.ResponseStatus = ResponseStatus.Completed; 
    } 
    catch(WebException e){ 

     restResponse.ResponseStatus = ResponseStatus.Error; 
     restResponse.ErrorMessage = e.Message; 
     restResponse.ErrorException = e; 
     var webResponse = (HttpWebResponse) e.Response; 
     if (webResponse != null){ 
      restResponse.StatusCode = webResponse.StatusCode; 
      restResponse.Headers = webResponse.Headers; 
     } 
     if (restResponse.StatusCode != HttpStatusCode.NotModified) 
      Console.WriteLine("An exception occured: " + e + "\r\n"); 
    }catch (Exception ex) { 
     restResponse.ResponseStatus = ResponseStatus.Error; 
     restResponse.ErrorMessage = ex.Message; 
     restResponse.ErrorException = ex; 
    } 

    if (httpResponse != null) 
     httpResponse.Close(); 

    return restResponse; 
} 

कृपया मदद: यहाँ विधि मैं बोल रहा हूँ है। मुझे नहीं पता क्या करना है। Google कुछ भी नहीं दिखाता है।

त्रुटि दिखाने से पहले मैं 22 सफल अनुरोध करने में सक्षम हूं।

संपादित मैं इसे एक सर्वर मुद्दे किया जा रहा करने के लिए नीचे संकुचित है। यह एएसपीनेट एमवीसी है और अपवाद तब होता है जब मैं क्लाइंट को 304 भेजता हूं। सर्वर कोड देखें:

private void ServeHttpStatusCode() { 
    Response.StatusCode = 304; 
    Response.Status = "304 Not Modified"; 
    Response.StatusDescription = "The resource you are requesting has not been modified"; 
    Response.ContentType = "application/json"; 
    Response.Write("{\"Error\":\"The resource you are requesting has not been modified\"}"); 
    Response.End(); 
    Response.Close(); 
} 
+0

इसका मतलब है कि सर्वर अच्छी तरह से अभिनय नहीं कर रहा है :) क्या आप कच्चे प्रतिक्रिया के बारे में देखने के लिए फिडलर या एथेरियल जैसे HTTP स्नफ़फर का उपयोग कर सकते हैं? – Skurmedel

+0

यह 22 बार काम कर रहा है, फिर बंद हो जाता है। अगर मैं अपना ऐप मारता हूं और शुरू करता हूं ... सभी 22 अनुरोधों के लिए अच्छा है। आप अभी भी सर्वर पर सोचते हैं? –

+0

उपरोक्त संपादन देखें। –

उत्तर

2
  • वहाँ ग्राहक और सर्वर के बीच एक प्रॉक्सी है?
  • क्या यह 22 अनुरोधों के बाद हमेशा विफल रहता है? अपवाद इंगित करता है कि कुछ UInt32 को पार्स नहीं किया जा सकता है।
  • क्या आपको सर्वर की तरफ अपवाद मिलते हैं?
+0

कोई प्रॉक्सी नहीं, लगभग 22 अनुरोध और कोई सर्वर अपवाद नहीं है। –

+0

क्या आप ग्राहक कोड दिखा सकते हैं? आप क्लाइंट साइड पर गलती से कुछ चीजों का पुन: उपयोग कर सकते हैं। – msms

+0

उपरोक्त संपादन देखें। –

1

यदि कोई और इस मुद्दे पर उत्तर की तलाश में इंटरनेट को खराब कर रहा है, तो मुझे कुछ कार्यात्मक परीक्षणों के साथ एक बहुत ही समस्या थी जो मैं लिख रहा था। वे http PUT का उपयोग कर वेबसर्वर पर सामग्री अपलोड कर रहे थे और उसके बाद सीधे http GET का उपयोग कर रहे थे।

GET Uint32 पार्स में एक ही त्रुटि के साथ विश्वसनीय रूप से विफल रहा। विंडोज़ बिल्ड ठीक था। निराशा में मैंने थ्रेड का उपयोग किया। सो (20) http अनुरोधों के बीच कुछ देरी डालने के लिए, और इसने त्रुटि को मंजूरी दे दी है। यकीन नहीं क्यों, लेकिन यह अब काम करता है, जो उत्पादन के सामान के लिए नहीं, मेरे परीक्षणों के लिए पर्याप्त है।

संबंधित मुद्दे