Android中如何使用这个WebService呢?

发布于 2024-11-28 07:51:20 字数 476 浏览 2 评论 0原文

我正在开发一个应用程序来使用Web服务,如何使用以下Web服务? http方法还是ksoap2?我尝试了 Ksoap2,似乎无法正确提取该 Web 服务,有人可以帮忙吗?提前致谢。

这是 wsdl: https://integrator-ut.vegaconnection.com/Authentication.svc? wsdl

那NAME_SPACE是:“http://tempuri.org/”方法是CreateToken吗?并且 SOAP_ACTION 是 http://tempuri.org/IAuthentication/CreateToken?...

I am developing a application to consume the web service, how to consume the following web-service? http method or ksoap2? I tried Ksoap2, seems can not extract this web service properly, anybody can help on this? thanks in advance.

Here is the wsdl: https://integrator-ut.vegaconnection.com/Authentication.svc?wsdl

Is that the NAME_SPACE is: "http://tempuri.org/" method is CreateToken? and the SOAP_ACTION is http://tempuri.org/IAuthentication/CreateToken?...

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

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

发布评论

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

评论(2

葬心 2024-12-05 07:51:20

请发布您的网络服务方法代码。

**Sample web service method**

public String Login(string userName, string pwd)  throws SoapFault   
{           

    String data = "";

    String serviceUrl =  "https://abc.com/xyz.svc";

    String serviceNamespace = "http://tempuri.org/";

    String soapAction = "http://abc.org/IAuthentication/CreateToken";

    String type_of_soap = "CreateToken";   

    try
    {
        SoapObject Request = new SoapObject(serviceNamespace, type_of_soap);
            //txtUserName,txtPassword these two are edit text ref variables but these are decalred before of this.
            Request.addProperty("userName", txtUserName.getText().toString());    
            Request.addProperty("password", txtPassword.getText().toString()); 


        System.out.println("GetRestaurantDetails:"+Request.toString()); 

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

        try
        {
            HttpTransportSE androidHttpTransport = new HttpTransportSE(serviceUrl);
            androidHttpTransport.call(soapAction, envelope);
        }
        catch(Exception e)
        {
            System.out.println("Webservice calling error ->"+e.toString());
        }

        SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
        data = response.toString();
        System.out.println("GetRestaurantDetails:"+response.toString());
        tv.setText(data );//this text view can be declared before this.

    }
    catch(Exception e)
    {
        System.out.println("Soap Method Error ->"+e.toString());    
    }        
    return data;
}   

please post ur web service method code.

**Sample web service method**

public String Login(string userName, string pwd)  throws SoapFault   
{           

    String data = "";

    String serviceUrl =  "https://abc.com/xyz.svc";

    String serviceNamespace = "http://tempuri.org/";

    String soapAction = "http://abc.org/IAuthentication/CreateToken";

    String type_of_soap = "CreateToken";   

    try
    {
        SoapObject Request = new SoapObject(serviceNamespace, type_of_soap);
            //txtUserName,txtPassword these two are edit text ref variables but these are decalred before of this.
            Request.addProperty("userName", txtUserName.getText().toString());    
            Request.addProperty("password", txtPassword.getText().toString()); 


        System.out.println("GetRestaurantDetails:"+Request.toString()); 

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

        try
        {
            HttpTransportSE androidHttpTransport = new HttpTransportSE(serviceUrl);
            androidHttpTransport.call(soapAction, envelope);
        }
        catch(Exception e)
        {
            System.out.println("Webservice calling error ->"+e.toString());
        }

        SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
        data = response.toString();
        System.out.println("GetRestaurantDetails:"+response.toString());
        tv.setText(data );//this text view can be declared before this.

    }
    catch(Exception e)
    {
        System.out.println("Soap Method Error ->"+e.toString());    
    }        
    return data;
}   
一向肩并 2024-12-05 07:51:20

如果你不想使用KSOAP,你可以使用httpUrlconnection和InputStream

        HttpURLConnection my_httpConnection = (HttpURLConnection) new URL("https://integrator-ut.vegaconnection.com/Authentication.svc?wsdl").openConnection();
        my_httpConnection.setRequestMethod("POST");
        my_httpConnection.setDoInput(true);
        my_httpConnection.setDoOutput(true);
        my_httpConnection.setRequestProperty("Content-type", "text/xml; charset=utf-8");



       OutputStream my_outPutStream = this.my_httpConnection.getOutputStream();
       Writer my_writer = new OutputStreamWriter(my_outPutStream);
       my_writer.write(YOUR_REQUEST); //YOUR_REQUEST is a String
       my_writer.flush();
       my_writer.close();           

       BufferedReader my_bufferReader = new BufferedReader(new InputStreamReader(this.my_httpConnection.getInputStream()));
        char[] buffer = new char[10000];
        int nbCharRead=0;
        try
        {
            while((nbCharRead = my_bufferReader.read(buffer, 0, 10000)) != -1)
            {
                 /* Your treatement : saving on a file/arraylist/etc

            }
        }

你必须根据你想要恢复的值创建字符串YOUR_REQUEST

它看起来像

<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" ... >
<soapenv:Header/>      
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope>

If you don't want to use KSOAP, you can use httpUrlconnection and InputStream

        HttpURLConnection my_httpConnection = (HttpURLConnection) new URL("https://integrator-ut.vegaconnection.com/Authentication.svc?wsdl").openConnection();
        my_httpConnection.setRequestMethod("POST");
        my_httpConnection.setDoInput(true);
        my_httpConnection.setDoOutput(true);
        my_httpConnection.setRequestProperty("Content-type", "text/xml; charset=utf-8");



       OutputStream my_outPutStream = this.my_httpConnection.getOutputStream();
       Writer my_writer = new OutputStreamWriter(my_outPutStream);
       my_writer.write(YOUR_REQUEST); //YOUR_REQUEST is a String
       my_writer.flush();
       my_writer.close();           

       BufferedReader my_bufferReader = new BufferedReader(new InputStreamReader(this.my_httpConnection.getInputStream()));
        char[] buffer = new char[10000];
        int nbCharRead=0;
        try
        {
            while((nbCharRead = my_bufferReader.read(buffer, 0, 10000)) != -1)
            {
                 /* Your treatement : saving on a file/arraylist/etc

            }
        }

You have to make the string YOUR_REQUEST based on the values ​​you want to recover

It look's like

<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" ... >
<soapenv:Header/>      
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文