WCF web service
我从拨打电话时遇到问题Android application
。如果我调用以下 URL,"http://10.0.2.2:80/WebService/WebServiceImpl.svc"
我会收到 response "200 OK"
,但是当我尝试在服务中调用该函数时,"http://10.0.2.2:80/WebService/WebServiceImpl.svc/Test"
我会收到 response "400 Bad request"
。
有人可以帮忙吗?
namespace WebService
{
public class WebServiceImpl : IWebServiceImpl
{
#region IRestServiceImpl Members
public string Test()
{
return "Test pass";
}
#endregion
}
}
namespace WebService
{
[ServiceContract]
public interface IWebServiceImpl
{
[OperationContract]
[WebInvoke(
Method = "GET")]
string Test();
}
}
安卓活动:
public void onClick(View v)
{
// TODO Auto-generated method stub
HttpClient client = new DefaultHttpClient();
String SERVER_HOST="10.0.2.2";
int SERVER_PORT = 80;
String URL = "http://10.0.2.2:80/WebService/WebServiceImpl.svc/Test";
HttpHost target = new HttpHost(SERVER_HOST, SERVER_PORT, "http");
HttpGet request = new HttpGet(URL);
try
{
HttpResponse response = client.execute(target,request);
HttpEntity entity = response.getEntity();
MessageBox(response.getStatusLine().toString());
}
catch(Exception e)
{
MessageBox("excepton");
MessageBox(e.toString());
}
}
public void MessageBox(String message){
Toast.makeText(this,message,Toast.LENGTH_LONG).show();
}