2012-03-26 5 views
1

jsonのWebサービスを作成して、画像とともにプロファイルデータを保存しました。私のサービスは正常に動作しますが、HttpWebRequestを返すサービスにデータを送信すると、「リモートサーバーがエラーを返しました:NotFound」Json webserviceからの画像を送信および受信しました。エラー:NotFound

私のコードは、この

void SendPost() 

{ 

      string webServiceAddress = @"http://localhost:51018/AMFDecember/WebService.asmx"; 
      string methodName = "Register"; 
      string url = string.Format("{0}/{1}", webServiceAddress, methodName); 

      HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); 
      webRequest.Method = "POST"; 
      webRequest.ContentType = "application/x-www-form-urlencoded"; 
      webRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallbackx), webRequest); 
     } 

void GetRequestStreamCallbackx(IAsyncResult asynchronousResult) 
     { 
      HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState; 
      // End the stream request operation 
      Stream postStream = webRequest.EndGetRequestStream(asynchronousResult); 
      StreamReader streamReader = new StreamReader(postStream); 
      string Response = streamReader.ReadToEnd(); 
string img=""; 

    try 
      { 

       string img = Convert.ToBase64String(imageBytes); 
      } 
      catch { } 
      // Create the post data 
      string postData = ""; 

     // <emailID>string</emailID> 
     //<pwd>string</pwd> 
     //<name>string</name> 
     //<img>base64Binary</img> 


      postData = "[email protected]&pwd=1234&name=test&img=" + Convert.ToBase64String(imageBytes) + ""; 


      byte[] byteArray = Encoding.UTF8.GetBytes(postData); 

      // Add the post data to the web request 
      try 
      { 
       postStream.Write(byteArray, 0, byteArray.Length); 
      } 
      catch { } 
      postStream.Close(); 

      // Start the web request 
      webRequest.BeginGetResponse(new AsyncCallback(GetResponseCallback), webRequest); 
     } 

     void GetResponseCallback(IAsyncResult asynchronousResult) 
     { 

      try 
      { 
       HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState; 
       HttpWebResponse response; 
       // End the get response operation 
       response = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult); 

       Stream streamResponse = response.GetResponseStream(); 
       StreamReader streamReader = new StreamReader(streamResponse); 
       string Response = streamReader.ReadToEnd(); 



       streamResponse.Close(); 
       streamReader.Close(); 
       response.Close(); 

      } 
      catch (WebException e) 
      { 
       // Error treatment 
       // ... 
      } 
     } 

答えて

1

私はあなたの問題は「のhttp:// localhost」がかもしれないと思うである - すなわち、あなたの携帯電話の中に - これは、サービスがローカルホスト上にある必要があります意味?

代わりに、代わりにPCのネットワークIPアドレスを使用してみてください。完全なIISまたはIISExpressを使用してサービスをホストする必要があります。

+0

あなたに感謝していますが、私はphone.iで実行していません。私のPC上でテストしています。テストhellowordメソッドは正常に動作します –

+0

あなたのシミュレータは電話です... localhostの別の定義を持つ適切な仮想マシン – Stuart

+0

しかし、私はlocalhostでこのサービスの別のメソッドを使用しているときにそれは動作しています –

関連する問題