Android调用wcf服务托管在控制台Windows应用程序中
您好我正在尝试将Android应用程序与在控制台获胜应用中托管的wcf服务连接
在本地网络中的
这就是我在网址中称之为我称之为http://192.168。 1.3:9000 / T_service当我想调用此服务的方法时
http://192.168.1.3:9000/T_service/getData并给我空白页面。???我不知道这是否可以
当我从.aspx文件中调用它时所有都很好,我在aspx中测试它以确保它有效。
我如何在android上使用它
Hi i am trying to connect android app with wcf service hosted in console win app
in local network this is how i call it in the url how i call it "http://192.168.1.3:9000/T_service" when i wanna call method of this service
http://192.168.1.3:9000/T_service/getData and gives me blank page.??? i dont know if this is ok
when i call it from .aspx file all is fine works perfect i tested it in aspx to make sure it works.
how i use it on android
SoapObject Reques = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(Reques);
HttpTransportSE hts = new HttpTransportSE(URL);
try{
hts.call(SOAP_ACTTION, soapEnvelope);
//SoapPrimitive resultString = (SoapPrimitive) soapEnvelope.getResponse();
SoapObject result = (SoapObject )soapEnvelope.getResponse();
result.getPropertyCount();
ArrayList<string> ar = new ArrayList<string>();
if(result.getPropertyCount() != 0){
for(int i = 0 ; i < result.getPropertyCount(); i++)
{
ar.add(result.getPropertyAsString(i));
}
}
else Toast.makeText(getApplicationContext(), "Pogresna lozinka!", Toast.LENGTH_LONG).show();
}catch(Exception er)
{
Toast.makeText(getApplicationContext(), er.toString(), Toast.LENGTH_LONG).show();
}
此代码在此行上给出错误hts.call(SOAP_ACTTION,soapEnvelope);
错误是=java.io.IOException:HTTP请求失败,HTTP状态:404
i尝试多一个代码
this code gives me error on this line hts.call(SOAP_ACTTION, soapEnvelope);
the error is = "java.io.IOException: HTTP request failed, HTTP status: 404"
i try one more code
try {
DefaultHttpClient client = new DefaultHttpClient();
// http get request
HttpGet request = new HttpGet(EMPLOYEE_SERVICE_URI);
// request.addHeader("f", "1");
// set the hedear to get the data in JSON formate
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
//get the response
HttpResponse response = client.execute(request);
HttpEntity entity = response.getEntity();
//if entity contect lenght 0, means no employee exist in the system with these code
if(entity.getContentLength() != 0) {
// stream reader object
Reader employeeReader = new InputStreamReader(response.getEntity().getContent());
//create a buffer to fill if from reader
char[] buffer = new char[(int) response.getEntity().getContentLength()];
//fill the buffer by the help of reader
employeeReader.read(buffer);
//close the reader streams
employeeReader.close();
//for the employee json object
JSONObject employee = new JSONObject(new String(buffer));
//set the text of text view
Toast.makeText(getApplicationContext(), employee.getString("1"), Toast.LENGTH_LONG).show();
//show hide layout
}
但是这给了我所有方式空结果entity.getContentLength()是0
可以帮一些人我用代码教程或者其他思考???
but this gives me all ways empty result entity.getContentLength() is 0
can some one help me with code tutorial or somethink else ???