无法传递参数 [英] Cannot pass parameter

查看:134
本文介绍了无法传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我有一个使用asp.net Web服务的Android应用程序.当我调用不需要参数传递的asp.net ws时,它可以正常工作.

但是另一个asp.net ws要求传递参数,我发送参数,但是它将参数接收为空值.我调试了一下,发现Android应用正确发送了参数. Asp.net ws将参数作为空值,并在不考虑这些变量的情况下将响应发送回去.

Android应用程式程式码:



Hi!

I have an Android app consuming asp.net web services. It works fine when I call asp.net ws that requires no parameter passing.

But another asp.net ws requires parameter passing, and I send the parameters, but it receives the parameters as null values. I debugged and saw that Android app send the parameters correctly. Asp.net ws takes parameters as null values, and send the response back without taking these variables into account.

The Android app code:



package com.wsImpl;

import org.apache.http.client.HttpClient;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope ;
import org.ksoap2.transport.AndroidHttpTransport;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class ErkActivity7
      extends Activity {

   private static final String NAMESPACE =
         "http://artisinerji.com";
   private static final String URL =
         "http://192.168.5.68:8080/erkService.asmx";
   private static final String SOAP_ACTION =
         "http://artisinerji.com/GetSumOfTwoInts";
   private static final String METHOD_NAME =
         "GetSumOfTwoInts";

   private static final String[] sampleACTV =
         new String[] { "android", "iphone", "blackberry" };

   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

      ArrayAdapter<String> arrAdapter =
            new ArrayAdapter<String>(this,
                  android.R.layout.simple_dropdown_item_1line,
                  sampleACTV);

		AutoCompleteTextView ACTV =
		      (AutoCompleteTextView) findViewById(
                            R.id.AutoCompleteTextView01);
		ACTV.setAdapter(arrAdapter);

		SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

		int num1 = 3; int num2 = 5;
		request.addProperty("num1",num1);
		request.addProperty("num2",num2);

		SoapSerializationEnvelope envelope = 
		      new SoapSerializationEnvelope(SoapEnvelope.VER11);

		envelope.dotNet = true;
		envelope.setOutputSoapObject(request);
		envelope.setAddAdornments(true);

		AndroidHttpTransport androidHttpTransport = 
		      new AndroidHttpTransport(URL);

		try {
		   androidHttpTransport.call(SOAP_ACTION, envelope);
		   SoapObject response = (SoapObject) envelope.bodyIn;

		   String result = response.getProperty(0).toString();
		   ACTV.setHint("Receivedddd: " + result.toString());
		} 
		catch (Exception e) {
		   e.printStackTrace();
		   ACTV.setHint("An Error Occured:" + e.getMessage());
		}

	}

}

推荐答案

您是否仅在模拟器上进行过尝试,如果是,请检查manifest.xml并确保

< uses-permission android:name ="android.permission.INTERNET"></uses-permission>

设置好了.我读到,使用模拟器时,这种类型的操作是无声的.

希望对您有帮助

达伦

也可以看看从Android访问Web服务的分步方法 [在CP上的 ^ ]
Have you only tried this on the emulator, if so check the manifest.xml and make sure

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

is set. I read that when using the emulator this type of action is silent.

Hope it helps

Darren

Also perhaps take a look at Step by Step Method to Access Webservice from Android[^] here on CP


嗨 我也有这个问题....我没有将参数传递给.net ws ...您已经解决了吗?
Hi I have this problem too....i connot pass parametter to .net ws... did you already solved?


这篇关于无法传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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