0

http://i.stack.imgur.com/pK9rm.png http://i.stack.imgur.com/27Qj0.png

我想使用 ksoap2 连接 Web 服务,我有一个工作示例,但是如何集成我的应用程序?

公共类 WebServiceDemoActivity 扩展 Activity {

  private static String SOAP_ACTION = "http://tempuri.org/UrunleriListele";
  private static String NAMESPACE = "http://tempuri.org/";
  private static String METHOD_NAME = "UrunleriListele";
  private static String URL = "http://services.annebebekavm.com/Service1.asmx?WSDL";

  Button btnFar,btnCel,btnClear;
  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);


    btnFar.setOnClickListener(new View.OnClickListener()
    {
              @Override
              public void onClick(View v)
              {

              SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);       


              request.addProperty("Fahrenheit",txtFar.getText().toString());


              SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

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

              try {
                    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);


                    androidHttpTransport.call(SOAP_ACTION, envelope);


                    SoapObject result = (SoapObject)envelope.bodyIn;

                    if(result != null)
                    {

                          txtFar.setText(result.getProperty(0).toString());
                    }
                    else
                    {
                          Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_LONG).show();
                    }
              } catch (Exception e) {
                    e.printStackTrace();
              }
              }
        });

}

}

4

1 回答 1

0

Please reconsider to use another client

http://code.google.com/p/android-ws-client/

you can create all classe what you need to. by one application copy libs to your project with your generate classes

Here is example it look really simple to

    Service servis = new Service();
    ServiceSoap soap12 = servis.getServiceSoap12();
    LoginParams inParams = new LoginParams();
    inParams.setLogin("user");
    inParams.setPassword("pass");
    inParams.setStrategy(LoginStrategy.NOHASHPASS); // even enums are supported
    LoginState result = soap.authorize(inParams);

    result.isLogin(); // boolean if is succesfull
于 2013-01-29T20:06:21.127 回答