This is how the service in asp.net looks like:
[ServiceContract(Namespace = "http://www.pluralsight.com/ws/")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class WeatherService
{
static Random _rand = new Random();
[OperationContract]
public string GetForecast(String zip)
{
switch (_rand.Next(3))
{
case 0:
return "Sunny and warm";
case 1:
return "Cold and rainy";
case 2:
return "Windy with a chance of snow";
default:
return "Invaild";
}
}
}
And This is how the Java calss looks like:
public static void GetForeCast(){
HttpClient httpClient = new DefaultHttpClient();
String url = "http://localhost:55196/WCFService1/";
try{
HttpGet method = new HttpGet(new URI(url));
HttpResponse response = httpClient.execute(method);
if(response != null){
Log.i("login", "recevied " + getResponse(response.getEntity()));
}else{
Log.i("login", "got a null response");
}
}catch(IOException e){
Log.e( "error", e.getMessage());
}catch(URISyntaxException e){
Log.e( "error", e.getMessage());
}
}
private static String getResponse(HttpEntity entity){
String response ="";
try{
int length = (int) entity.getContentLength();
StringBuffer sb = new StringBuffer(length);
InputStreamReader is = new InputStreamReader(entity.getContent());
char buff[] = new char[length];
int cnt;
while((cnt = is.read(buff,0,length))>0){
sb.append(buff,0,cnt);
}
response = sb.toString();
is.close();
}catch(IOException e){
e.printStackTrace();
}
return response;
}
I don't know what the url I should send in? Should I call the weatcherservice.svc ? and how should I call the method getForecast from the service?