我正在尝试将我的android设备与简单的C#网络服务连接,但出现此错误
org.xmlpull.v1.XmlpullparserException:预期:START_TAG {http://schemas.xmlsoap.org/soap/envelope/}信封(java.io.inputStreamReader@1db98270中的位置:START_TAG @ 2:7)
这是我的代码:
package com.example.khalifa_.webservice;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity
{
/** Called when the activity is first created. */
private static final String SOAP_ACTION = "http://tempuri.org/findContact";
private static final String OPERATION_NAME = "findContact";// your webservice web method name
private static final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
private static final String SOAP_ADDRESS = "http://192.168.1.3:29824/Service.asmx";
// for the SOAP_ADDRESS, run your web service & see
//your web service Url :1506/WebSite3/Service.asmx ,1052 will be change according to your PC
TextView tvData1;
EditText edata;
Button button;
String studentNo;
//http://localhost:1827/WebSite1/Service.asmx/HelloWorld
//http://10.0.2.2:1827/WebSite1/Service.asmx
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
tvData1 = (TextView)findViewById(R.id.textView1);
button=(Button)findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);
PropertyInfo propertyInfo = new PropertyInfo();
propertyInfo.type = PropertyInfo.STRING_CLASS;
propertyInfo.name = "eid";
edata =(EditText)findViewById(R.id.editText1);
studentNo=edata.getText().toString();
request.addProperty(propertyInfo, studentNo);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
try {
httpTransport.call(SOAP_ACTION, envelope);
Object response = envelope.getResponse();
tvData1.setText(response.toString());
} catch (Exception exception) {
tvData1.setText(exception.toString()+" Or enter number is not Available!");
}
tvData1 = (TextView)findViewById(R.id.textView1);
}
});
//client = new DefaultHttpClient();
//new Read().execute("text");
}
}
参考方案
您必须在后台线程中编写代码。使用asynctask作为后台线程。有关更多信息,请refer this。
android-android studio模拟器中的SSL问题,在手机上可以正常工作 - java我有一个可以通过https调用网络服务的应用程序。当我在手机上运行apk时,效果很好。但是,在模拟器中,所有通过POST的SSL请求均失败,并显示以下信息: 读取错误:ssl = 0xb402be00:SSL库失败,通常是一个协议 错误 错误:100c50bf:SSL例程:ssl3_read_bytes:NO_RENEGOTIATION(外部/无聊的sl /…
绑定Java库Xamarin.Android - java我花了两天时间在每个论坛,文档,tuto,博客等上寻找答案。我为实习生启动了一个Android应用程序,因为我不懂Java,所以用xamarin C#开发了它。直到最近一切都还不错,但现在我需要集成一个SDK才能在应用程序中使用POS(销售点),但是该库是用Java编写的,即使跟随文档或辅导老师,我也无法将其与xamarin绑定(我什至无法调试)。这里有人已…
Android Studio报告“android sdk解析不正确” - java我只是将一个android项目从eclipse迁移到了android studio,但是当我尝试对其进行编译时,出现错误“android sdk被错误地解析”。有什么帮助吗? 参考方案 尝试将Android Studio配置为指向您的SDK安装。
首先关注EditText清晰文本-Android - javaIt's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current fo…
Java:正则表达式模式匹配器是否有大小限制? - java我的模式类似于OR:“word1 | word2 | word3”我大约有800个字。可能有问题吗? 参考方案 您仅受记忆和理智的限制。 :)