Click here to Skip to main content
15,900,468 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all, I'm a newbie in windows 8 platform. I'm creating a login page in an windows phone 8 app using visual studio 2012 ultimate. My login function is in the .asmx web service which is under framework 3.5. How can I make my button to send username and password to the web service?
Posted

1 solution

You can use the HttpClient to connect to the web service and either post the message content as necessary, or just use the url with the paramaters as required.

For more information, have a look at the Task Parallelism on MSDN
http://msdn.microsoft.com/en-us/library/dd460717.aspx[^]
There is also a good article(s) on CP
Task Parallel Library: 1 of n[^]

For eg.

C#
var handler = new HttpClientHandler()
{
     Proxy = System.Net.HttpWebRequest.GetSystemWebProxy(),
     MaxRequestContentBufferSize = 30 * 10000000
};

_client = new HttpClient(handler, true);

var task = _client.GetStringAsync("http://myservice.asmx?username=theusername&password=thepassword")
				  .ContinueWith(messageWithResult => 
				  {
					  var result = messageWithResult.Result;
				  });

// Alternatively if you need to post the message content
var dic = new Dictionary<string, string>();
dic.Add("Username", "theusername");
dic.Add("Password", "password");

FormUrlEncodedContent content = new FormUrlEncodedContent(dic);
HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, "http://myservice.asmx");
message.Content = content;

var task = _client.SendAsync(message)
				  .ContinueWith(messageWithResult => 
				  {
					  var readTask = messageWithResult.Result.Content.ReadAsStringAsync().ContinueWith(
						  stringMessageResult =>
						  {
							  var result = stringMessageResult.Result;
						  });

					  readTask.Wait();
				  });

task.Wait();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900