如何调用 .NET Web 方法?

发布于 2024-12-10 10:58:16 字数 271 浏览 0 评论 0原文

首先感谢您的所有回答,这个主题可能会被关闭,因为我已经做了我想要的东西。我在下面提到了如何调用 .NET webmethod。

http://aaarkonusurum.blogspot.com/2011 /10/android-ile-dataset-donen-bir-net.html

Firstly thank you for all answers, this subject may be closed because I made what I want already. I mentioned about how to call a .NET webmethod below.

http://aaarkonusurum.blogspot.com/2011/10/android-ile-dataset-donen-bir-net.html

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

太阳男子 2024-12-17 10:58:16

如果您只需要一个调用 Web 服务方法的方法,请使用以下方法:

public static SoapPrimitive callWebServiceMethod(String url,
            String namespace, String methodName,
            HashMap<String, Object> parameters, String soapAction)
            throws IOException, XmlPullParserException, SoapFault {

        SoapObject request = new SoapObject(namespace, methodName);

        if (parameters != null) {
            String[] keys = new String[0];
            keys = (String[]) parameters.keySet().toArray(keys);
            Object[] vals = (Object[]) parameters.values().toArray();

            for (int i = 0; i < parameters.size(); i++) {
                request.addProperty(keys[i], vals[i]);
            }
        }

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
        envelope.dotNet = true;

        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(url,
                60 * 1000);

        androidHttpTransport.call(soapAction, envelope);
        return (SoapPrimitive) envelope.getResponse();
    }

并在您的活动中:

private static final String NAMESPACE = "http://tempuri.org/";
private static final String METHOD_NAME = "MethodName";
private static final String SOAP_ACTION = "http://tempuri.org/MethodName";

        String url = "http://...";

        HashMap<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("param1", param1);
        parameters.put("param2", param2);
        //...

        SoapPrimitive response = callWebServiceMethod(url,
                NAMESPACE, METHOD_NAM, parameters,
                SOAP_ACTION);

        String webServiceResult = response.toString();

If you need only a method for calling a webservice method, use this:

public static SoapPrimitive callWebServiceMethod(String url,
            String namespace, String methodName,
            HashMap<String, Object> parameters, String soapAction)
            throws IOException, XmlPullParserException, SoapFault {

        SoapObject request = new SoapObject(namespace, methodName);

        if (parameters != null) {
            String[] keys = new String[0];
            keys = (String[]) parameters.keySet().toArray(keys);
            Object[] vals = (Object[]) parameters.values().toArray();

            for (int i = 0; i < parameters.size(); i++) {
                request.addProperty(keys[i], vals[i]);
            }
        }

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
        envelope.dotNet = true;

        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(url,
                60 * 1000);

        androidHttpTransport.call(soapAction, envelope);
        return (SoapPrimitive) envelope.getResponse();
    }

and in your activity:

private static final String NAMESPACE = "http://tempuri.org/";
private static final String METHOD_NAME = "MethodName";
private static final String SOAP_ACTION = "http://tempuri.org/MethodName";

        String url = "http://...";

        HashMap<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("param1", param1);
        parameters.put("param2", param2);
        //...

        SoapPrimitive response = callWebServiceMethod(url,
                NAMESPACE, METHOD_NAM, parameters,
                SOAP_ACTION);

        String webServiceResult = response.toString();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文