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 ?...

4

2 回答 2

1

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

**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;
}   
于 2011-08-08T10:55:04.377 回答
0

如果不想使用 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>
于 2011-08-10T08:44:56.423 回答