Reputation: 115
I am building my first app for windows application. My requirement is that- On clicking a button i want to navigate to another page and in that page i want the data to be displayed directly from a soap web service also by performing xml parsing.
Button event code:
private void button1_Click(object sender, RoutedEventArgs e)
{
KejriwalService.arvindSoapClient client = new KejriwalService.arvindSoapClient();
client.getarvindNewsCompleted += new EventHandler<KejriwalService.getarvindNewsCompletedEventArgs>(client_getarvindNewsCompleted);
}
void client_getarvindNewsCompleted(object sender, KejriwalService.getarvindNewsCompletedEventArgs e)
{
textBlock1.Text = e.Result.ToString();
}
I am not getting any result from here. Can anyone please help. I want to extract 3 text fields and 1 image from this web method
Upvotes: 1
Views: 1174
Reputation: 448
Just check your web service. Your code is perfect but you need to change your web service. Donot return string from your web method but return the xml
Upvotes: 1
Reputation: 3976
You had associate the delegate but you have not called the method. You probably have a method like
KejriwalService.arvindSoapClient.DoSomethingAsync()
This will fire the event and after that it will trigger the client_getarvindNewsCompleted
method when the responde from the WebService comes.
Edit
Just remember to use the [WebMethod]
attribute in you WebService method.
public class Service1 : System.Web.Services.WebService
{
[System.Web.Services.WebMethod]
public string getarvindNews()
{
return "I am a string";
}
}
In you code you call this async like this:
private void button1_Click(object sender, RoutedEventArgs e)
{
KejriwalService.arvindSoapClient client = new arvindSoapClient();
client.getarvindNewsCompleted += new
EventHandler<getarvindNewsCompletedEventArgs>(client_getarvindNewsCompleted);
//Call the method async and get its result in client_getarvindNewsCompleted
client.getarvindNewsAsync();
}
void client_getarvindNewsCompleted(object sender, getarvindNewsCompletedEventArgs e)
{
textBlock1.Text = e.Result.ToString();
}
Upvotes: 1