2013-10-09 58 views
-1

我有一个Web服务托管在与SQL Server交互的服务上。 我必须开发一个Windows Phone 8应用程序,该应用程序应该与该Web服务进行交互以从服务器获取数据。 我为使用Web客户端,但得到的回应:远程服务器返回错误NOTFOUND” 我不知道如何调用一个方法.. ,哪一个更好 了HTTPClient Web客户端 或任何其他方法在Windows Phone 8中调用Web服务方法应用

回答

-1

我想这应该是帮助您:

private void Button_Click_1(object sender, RoutedEventArgs e) 
{ 
    // Create a new HttpWebRequest object. 
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.example.com/webservicelogin/webservice.asmx/ReadTotalOutstandingInvoice"); 

    request.ContentType = "application/x-www-form-urlencoded"; 
    request.UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; Touch)"; 
    request.CookieContainer = cookie; 

    // Set the Method property to 'POST' to post data to the URI. 
    request.Method = "POST"; 

    // start the asynchronous operation 
    request.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), request); 

} 

private void GetRequestStreamCallback(IAsyncResult asynchronousResult) 
{ 
    HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; 

    // End the operation 
    Stream postStream = request.EndGetRequestStream(asynchronousResult); 

    //postData value 
    string postData = "xxxxxxxxxx"; 

    // Convert the string into a byte array. 
    byte[] byteArray = Encoding.UTF8.GetBytes(postData); 

    // Write to the request stream. 
    postStream.Write(byteArray, 0, postData.Length); 
    postStream.Close(); 

    // Start the asynchronous operation to get the response 
    request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request); 

} 

private void GetResponseCallback(IAsyncResult asynchronousResult) 
{ 

      HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; 
      // End the operation 

      HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult); 

      Stream streamResponse = response.GetResponseStream(); 

      StreamReader streamRead = new StreamReader(streamResponse); 
      string read = streamRead.ReadToEnd(); 

      //respond from httpRequest 
      TextBox.Text = read; 

      // Close the stream object 
      streamResponse.Close(); 
      streamRead.Close(); 
      response.Close(); 
} 
0
public ConstructoreName() 
    { 
     InitializeComponent(); 

     ServiceReferenceCustomer.OfferhutCustomerClient ohCustomer = new ServiceReferenceCustomer.OfferhutCustomerClient(); 

     ohCustomer.getOfferAsync(3); //here getOffer is a method and 3 is a parameter 
     ohCustomer.getOfferCompleted += new EventHandler<getOfferCompletedEventArgs>(getOffer_completed); 
    } 

void getOffer_completed(object sender, getOfferCompletedEventArgs e) 
    { 
     ServiceReferenceCustomer.offer res; 
     res = e.Result; 

     offerTitle.Text = res.title; 
     offerFirstPara.Text = res.shopName + " \n" + res.title + " \n" + res.date; 
     offerSecendPara.Text = res.description; 
    } 

我认为这是给你的帮助..

相关问题