2013-04-02 4 views
1
package com.example.weblab; 
import org.apache.http.protocol.HTTP; 
import org.ksoap2.SoapEnvelope; 
import org.ksoap2.serialization.PropertyInfo; 
import org.ksoap2.serialization.SoapObject; 
import org.ksoap2.serialization.SoapPrimitive; 
import org.ksoap2.serialization.SoapSerializationEnvelope; 
import org.ksoap2.transport.HttpTransportSE; 
import android.util.Log; 


public class WebServiceCaller { 

private final String NAMESPACE="http://tempuri.org/"; 
private final String URL="http://10.0.2.2:8080/Service1.asmx?WSDL"; 

public String authenticateUser(String usern,String passw) 
{ 
    String result = ""; 
    final String SOAP_ACTION="http://tempuri.org/AuthenticateUser"; 

    final String METHOD_NAME="GetUserName"; 

    SoapObject request=new SoapObject(NAMESPACE, METHOD_NAME); 

    PropertyInfo prinfo=new PropertyInfo(); 
    prinfo.setName("name"); 
    prinfo.setValue(usern); 
    prinfo.setType(String.class); 
    request.addProperty(prinfo); 

    SoapSerializationEnvelope envelop=new  SoapSerializationEnvelope(SoapEnvelope.VER11);//ver11 version 
    envelop.dotNet=true;//only for dotnet 

    envelop.setOutputSoapObject(request); 
    HttpTransportSE httptransportse=new HttpTransportSE(URL); 
    try{ 
    httptransportse.call(SOAP_ACTION, envelop); 

    SoapPrimitive response=(SoapPrimitive)envelop.getResponse(); 

    Log.i("myapp",response.toString()); 

     result = response.toString(); 

    }catch (Exception e) { 

     e.printStackTrace(); 

    } 

    return result; 

} 
} 

04-02 09:39:26.044: W/System.err(13741): org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <html>@2:7 in [email protected])안드로이드 KSOAP2 웹 서비스 오류

나는이 오류가 발생합니다.

이것은 KSOAP 웹 서비스의 전체 코드입니다. 현재 Eclipse에서 에뮬레이터로 로컬 호스트 서버를 실행하고 있습니다.

+0

처럼 다른 스레드에서 코드를 사용하려고? – Raghunandan

+0

여기서 코드의 네임 스페이스는 무엇입니까? – Yugesh

+0

코드 URL 및 네임 스페이스가 누락되었습니다. – Yugesh

답변

0

는 URL이이

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 

StrictMode.setThreadPolicy(policy);