Android的KSOAP2 Web服务错误 [英] Android KSOAP2 web service Error

查看:130
本文介绍了Android的KSOAP2 Web服务错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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;

}   
}

九月四日至2日:39:26.044:W / System.err的(13741):org.xmlpull.v1.XmlPullParserException:期望值START_TAG {http://schemas.xmlsoap.org/soap /信封/}信封(位置:START_TAG< HTML> @ 2:7 java.io.InputStreamReader@40d38638)

我得到的,当我尝试我的Andr​​oid应用程序连接到它在本地主机上运行的Web服务这个错误。

I get this error when i trying to connect my android application to a web service which is running in local host.

这是全code为KSOAP Web服务。 目前我正在运行的本地主机服务器与我在Eclipse模拟器。

This is the full code for the KSOAP web service. Currently I'm running a local host server with my emulator in Eclipse.

推荐答案

试图在另一个线程像这样

try to use your code within another thread like this

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

 StrictMode.setThreadPolicy(policy); 

这篇关于Android的KSOAP2 Web服务错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆