所以我在尝试将 6 个变量发送到 Web 服务时遇到问题(http://hydra.chorleywood.org/hydradevices/devicesmanagement.asmx)
我在运行 4.2 API 17 的 android 中使用 ksoap2-android
每次我按下与之关联的按钮时,我的程序都会崩溃。我浏览了许多教程,并按照他们所做的那样做,但无论我是在 eclipse 中运行它还是导出并在我的手机上运行它,它都对我不起作用。
这是代码的相关部分
private static final String NAMESPACE = "http://hydra.chorleywood.org";
private static final String URL="http://hydra.chorleywood.org/hydradevices/devicesmanagement.asmx";
private static final String METHOD1_SOAP_ACTION_URL = "http://hydra.chorleywood.org/addNewDevice";
private static final String METHOD_NAME1 = "addNewDevice";
final Button status_button = (Button) findViewById(R.id.device_status);
status_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
// setting my variables
String EUI64 = "EHF7980HY3G793HG393GF737GH80G7";
String HashCode = "MB2GPD";
int DeviceTypeID = 528391;
String subType = "Weighing Scales";
String Manufacturer = "Samsung";
String SerialNumber = "8476403967";
// setting connectionas
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
envelope.dotNet = true;
// setting informaiton to be sent
request.addProperty("EUI64", EUI64);
request.addProperty("HashCode", HashCode);
request.addProperty("DeviceTypeID", DeviceTypeID);
request.addProperty("subType", subType);
request.addProperty("Manufacturer", Manufacturer);
request.addProperty("SerialNumber", SerialNumber);
// setting request to be sent out
envelope.setOutputSoapObject(request);
try
{
androidHttpTransport.call(METHOD1_SOAP_ACTION_URL, envelope);
//java.lang.String receivedString = (String)envelope.getResponse();
//java.lang.Boolean receivedBoolean = (Boolean)envelope.getResponse();
Object result = envelope.getResponse();
/**if(receivedBoolean = true) {
Context context = getApplicationContext();
CharSequence text = "testing toast";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}**/
}
catch(Exception e)
{
}
}
我已经在清单中设置了权限,我不确定到底出了什么问题,有人知道吗?
我尝试了不同的 API,但仍然无法正常工作。我非常感谢有关此主题的任何帮助,到目前为止,我已经投入了一周的时间,而我只是在兜圈子。
我已经从字面上复制粘贴了其他人的网络服务(我认为这是一个活动服务器)并尝试运行他们的确切代码,但这似乎也不起作用。也许这会帮助你找出我遇到的问题。
非常感谢,
查理