I am developing an app which uses third party .asmx
web service. And I am using PCL(Portable class Libraries) in my app.
So I wanted to consume those .asmx
web services in my app. Problem is PCL doesn't support traditional web service viz .asmx
. It supports WCF
web services.
I have read many articles, they suggests me that from wsdl
write WCF
web service. But since all web services are third party, I need to write proxy in client app (Where web service is being called) such that it will convert WCF
call to .asmx
.
Also I have tried this example using PCL. I am using this asmx web service
public class PerformLogIn : ILogInService
{
public string LogIn(string code)
{
ServiceReference1.WeatherSoapClient obj = new ServiceReference1.WeatherSoapClient();
obj.GetCityForecastByZIPAsync(code);
ServiceReference1.WeatherReturn get = new ServiceReference1.WeatherReturn();
return (get.Temperature);
}
But I am not getting any result. So do anybody have idea how to do that??
Eureka I found it..
Use following code snippet
public class PerformLogIn : ILogInService
{
public void LogIn(string code)
{
ServiceReference1.WeatherSoapClient obj = new ServiceReference1.WeatherSoapClient(
new BasicHttpBinding(),
new EndpointAddress("http://wsf.cdyne.com/WeatherWS/Weather.asmx"));
obj.GetCityForecastByZIPAsync(code);
obj.GetCityForecastByZIPCompleted+=getResult;
}
void getResult(Object sender,GetCityForecastByZIPCompletedEventArgs e)
{
string error = null;
if (e.Error != null)
error = e.Error.Message;
else if (e.Cancelled)
error = "cancelled";
var result = e.Result;
}
}
So your response from web service is being stored in result
variable. Just fetch the data whatever needed and return it to calling client.