Ksoap2 .NET Web服务连接

时间:2013-01-29 14:18:05

标签: android .net web-services ksoap2 android-ksoap2

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

我想使用kso​​ap2连接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();
              }
              }
        });

}

}

1 个答案:

答案 0 :(得分:0)

请重新考虑使用其他客户

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

你可以创建你需要的所有classe。 通过一个应用程序副本库到您的项目 与您的生成类

这是一个非常简单的例子

    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