2013-04-02 248 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])的Android KSOAP2 Web服務錯誤

我得到這個錯誤,當我嘗試我的Android應用程序連接到在本地主機上運行的Web服務。

這是KSOAP網絡服務的完整代碼。 目前我在Eclipse中使用我的模擬器運行本地主機服務器。

+0

哪裏是你的網址是什麼? – Raghunandan

+0

其中是代碼中的名稱空間。 – Yugesh

+0

在您的代碼中URL和名稱空間丟失。 – Yugesh

回答

0

嘗試另一個線程中使用這樣的代碼

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

StrictMode.setThreadPolicy(policy); 
相關問題