Click here to Skip to main content
15,885,061 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
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
Java
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();  	
				 }


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


Java
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
            }

but this gives me all ways empty result entity.getContentLength() is 0

can some one help me with code tutorial or somethink else ???
Posted
Updated 26-Jun-14 21:12pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900