- Forum posts: 8
Feb 27, 2014, 11:24:42 AM via Website
Feb 27, 2014 11:24:42 AM via Website
I have created a simple WCF service and deploy it on internal server and trying to access it in my android application. Below is the code.
WCF: IService.cs
[XmlSerializerFormat(Style = OperationFormatStyle.Document, Use = OperationFormatUse.Literal)]
[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Xml,
Method = "GET", ResponseFormat = WebMessageFormat.Xml, UriTemplate = "/GetUserForTest")]
string GetUserForTest();
Service.cs
public string GetUserForTest()
{
return "Result from Service";
}
Code for Android:
Button bSearchUser = (Button) findViewById(R.id.bSearchUser);
TextView firstName = (TextView) findViewById(R.id.txtFstName);
bSearchUser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet request = new HttpGet(User_Service_URL+"/GetUserForTest");
request.setHeader("Accept", "application/xml");
request.setHeader("Content-type", "application/xml");
try {
HttpResponse response = httpClient.execute(request);
HttpEntity entity = response.getEntity();
String result = EntityUtils.toString(entity);
firstName.setText(result);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});
The Client code[android code] returns: <html><body><p>File does not exist</p></body></html>
Please let me know what is going wrong in my code.
Thanks in Advance.
— modified on Feb 27, 2014, 11:34:10 AM