0

我想使用 KSOAP2 创建 Web 服务的连接,我已经完成了代码并且它出现了错误,所以请建议我在哪里做错了。我还需要一些关于 Web 服务方面的帮助,什么是命名空间,方法我们调用,soap_action,url 以及一些关于我们在 web 服务中使用的方法。我搜索了很多,但没有找到任何关于 web 服务的完整描述

 public class Web_ServicesActivity extends Activity {
    private static String SOAP_ACTION = "http://service.fun2shoot.com/getLive";

    private static String NAMESPACE = "http://service.fun2shoot.com/";
    private static String METHOD_NAME = "getLive";

    private static String URL = "http://119.82.75.91:8084/Fun2Shoot-WebService/Fun2ShootAndroid?wsdl";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        System.out
                .println("After mail******************************************");
        // Initialize soap request + add parameters
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        System.out.println("****************After Request call");
        // Use this to add parameters
        // request.addProperty("Parameter","Value");

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

        // Needed to make the internet call
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        try {
            // this is the actual part that will call the webservice
            androidHttpTransport.call(SOAP_ACTION, envelope);
        } catch (Exception e) {
            e.printStackTrace();
        }

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

        if (result != null) {
            TextView t = (TextView) this.findViewById(R.id.tv);
            System.out
                    .println("***************************************Inside null condition");
            // Get the first property and change the label text
            t.setText("SOAP response:\n\n" + result.getProperty(0).toString());
        }

    }
}
4

1 回答 1

0

您可以在您的项目中添加库,Build Path并使用本教程如何创建基于 java 的 Web 服务供您参考在 Java 中创建 Web 服务

如果您对此有任何疑问或任何其他疑问,可以写信给我。

于 2012-06-15T04:55:05.473 回答