【问题标题】:Send and Rcived Image from Json webservice error: NotFound从 Json Web 服务错误发送和接收图像:NotFound
【发布时间】:2012-03-26 14:14:10
【问题描述】:

我创建了一个 JSON Web 服务来保存带有图像的配置文件数据。我的服务正常工作,但是当向服务 HttpWebRequest 发送数据时返回“远程服务器返回错误: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 = "emailID=pr@pr.pr&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
                // ...
            }
        }

【问题讨论】:

    标签: json web-services windows-phone-7 windows-phone


    【解决方案1】:

    我认为您的问题可能是“http://localhost” - 这意味着服务应该在 localhost 上 - 即在您的手机中?

    也许尝试使用您 PC 的网络 IP 地址 - 您可能需要使用完整的 IIS 或 IISExpress 来托管您的服务。

    【讨论】:

    • 谢谢你先生,但我没有在手机上运行。我在我的电脑上测试过。当测试 helloword 方法时它工作正常
    • 但是你的模拟器是一部手机……它是一个适当的虚拟机,有一个单独的 localhost 定义
    • 但是先生,当我在本地主机上使用此服务的另一种方法时,它正在工作
    猜你喜欢
    • 1970-01-01
    • 2011-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-25
    • 2013-01-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多