【问题标题】:Ksoap2 .NET web service connectionKsoap2 .NET Web 服务连接
【发布时间】:2023-03-22 10:42:01
【问题描述】:

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();
              }
              }
        });

}

}

【问题讨论】:

  • 我会推荐你​​使用wsclient++。
  • 我使用 ksoap2 得到了它,但现在我尝试解析我对 webservice 的响应
  • 或者使用这个code.google.com/p/android-ws-client这个更好。

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


【解决方案1】:

请重新考虑使用其他客户端

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

您可以根据需要创建所有类。 通过一个应用程序将库复制到您的项目 用你的生成类

这是一个看起来很简单的例子

    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

【讨论】:

  • 能否通过sql查询连接到客户端或服务器?
  • 我不知道你要什么。这是客户端。
  • 对不起,我的英语说得不太好:) 我想告诉你,我可以用你的代码连接我的数据库吗?我希望我能正确解释我的问题:)
  • 看你必须建立与数据库连接的Web服务并将获取的记录作为集合发送给客户端。客户端(Android)接收数据并通过某种方式(KSoap,wsclient++,...)将该数据绑定到您的对象。所以有可能。
  • (数据库服务器) SoapClient(android)
猜你喜欢
  • 2013-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多