-1

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

4

2 回答 2

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;
    }

我想这对你有帮助..

于 2014-05-30T04:00:50.023 回答
-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();
}
于 2013-10-09T10:07:37.840 回答