Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android/eclipse中的web服务_Android_Eclipse_Web Services - Fatal编程技术网

android/eclipse中的web服务

android/eclipse中的web服务,android,eclipse,web-services,Android,Eclipse,Web Services,我需要通过soap方法使用来自android/eclipse的web服务 也就是说,我必须给出一个输入,并根据用户的输入显示web服务的适当结果。如何做到这一点 java类 public class Demo_webserviceActivity extends Activity { /** Called when the activity is first created. */ private static String NAMESPACE = "http://tempuri.or

我需要通过soap方法使用来自android/eclipse的web服务

也就是说,我必须给出一个输入,并根据用户的输入显示web服务的适当结果。如何做到这一点

java类

public class Demo_webserviceActivity extends Activity
{ 
/** Called when the activity is first created. */

   private static String NAMESPACE = "http://tempuri.org/";
   private static String METHOD_NAME = "GetName";
    private static String SOAP_ACTION = "http://tempuri.org/GetName";
    private static String URL = "http://122.248.240.105:234/Service1.asmx";

   Button btnFar;
   EditText txtFar,txtCel;


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

   btnFar = (Button)findViewById(R.id.btnFar);

   txtFar = (EditText)findViewById(R.id.txtFar);
   txtCel = (EditText)findViewById(R.id.txtCel);

   btnFar.setOnClickListener(new View.OnClickListener()
   {

   public void onClick(View v)
   {
     //Initialize soap request + add parameters
     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);       

     //Use this to add parameters
     request.addProperty("Fahrenheit",txtFar.getText().toString());

     //Declare the version of the SOAP request
     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

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

     try 
     {
         HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

         //this is the actual part that will call the webservice
         androidHttpTransport.call(SOAP_ACTION, envelope);

         // Get the SoapResult from the envelope body.
         SoapObject result = (SoapObject)envelope.bodyIn;

         if(result != null)
         {
          //Get the first property and change the label text
           txtCel.setText(result.getProperty(0).toString());
         }
         else
         {
           Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_SHORT).show();
         }
    }
    catch (Exception e)
    {
       e.printStackTrace();
       }
     }
       });
    } 
 }
网络方法

public class GetName 
{
public String GetName(String Fahrenheit){
    return(Fahrenheit);
}
}
logcat

06-12 17:40:00.322: W/InputManagerService(59): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@44f60478 (uid=10040 pid=345)
 06-12 17:40:00.352: W/IInputConnectionWrapper(345): showStatusIcon on inactive InputConnection
 06-12 17:40:07.292: D/AndroidRuntime(352): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
06-12 17:40:07.292: D/AndroidRuntime(352): CheckJNI is ON
06-12 17:40:07.477: D/AndroidRuntime(352): --- registering native functions ---
06-12 17:40:08.062: D/AndroidRuntime(352): Shutting down VM
06-12 17:40:08.062: D/dalvikvm(352): Debugger has detached; object registry had 1 entries
06-12 17:40:08.102: I/AndroidRuntime(352): NOTE: attach of thread 'Binder Thread #3' failed
06-12 17:40:08.502: D/AndroidRuntime(360): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
06-12 17:40:08.502: D/AndroidRuntime(360): CheckJNI is ON
06-12 17:40:08.633: D/AndroidRuntime(360): --- registering native functions ---
06-12 17:40:09.152: I/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.demo.webser/.Demo_webserviceActivity }
06-12 17:40:09.222: D/AndroidRuntime(360): Shutting down VM
06-12 17:40:09.222: D/dalvikvm(360): Debugger has detached; object registry had 1 entries
06-12 17:40:09.252: I/AndroidRuntime(360): NOTE: attach of thread 'Binder Thread #3' failed
06-12 17:40:00.322:W/InputManagerService(59):在非焦点客户端com.android.internal.view.IInputMethodClient$Stub上启动输入$Proxy@44f60478(uid=10040 pid=345)
06-12 17:40:00.352:W/IIInputConnectionWrapper(345):在非活动输入连接上显示状态图标

06-12 17:40:07.292:D/AndroidRuntime(352):>>>>>>>>>>>>>>AndroidRuntime开始>AndroidRuntime开始您的方向是正确的,即您在android中编写的代码是正确的。只需确保您编写的soap操作、方法、URl和命名空间是正确的。 如果您对此或任何其他疑问有任何疑问,请写信给我

下面是在android中访问web服务的基本android教程


要在java中创建Web服务,请使用本教程

您应该使用
SoapPrimitive results=(SoapPrimitive)envelope.getResponse()
而不是
SoapObject result=(SoapObject)envelope.bodyIn字符串
而不是
对象

+1 Samir和-1@Rohith没有搜索一分钟paresh我将用我迄今为止所做的编辑我的问题如果我遵循你的答案,可能会重复。这些行显示错误txtCel.setText(result.getProperty(0.toString());我可以删除getProperty(0)并使用result.toString()尝试什么?它显示与“找不到名称”相同的结果…我认为web方法可能有问题,我的web方法源是否正确?您是否在webservice中的GetName()之前添加了[WebMethod]?然后发布你的logcat数据。是的,我已经用logcat添加了web方法的源代码,请再次访问我的问题…给出的代码是“编写”。请确保正确部署该服务。请按照我在回答中给出的链接检查web服务。我已经使用该链接创建了web服务及其工作情况。如果仍然存在问题,请给我写信。