Autore Topic: SOAP Vs KSOAP2  (Letto 865 volte)

Offline cretara

  • Nuovo arrivato
  • *
  • Post: 9
  • Respect: +1
    • Mostra profilo
  • Dispositivo Android:
    Virtual devices
  • Sistema operativo:
    windows7
SOAP Vs KSOAP2
« il: 29 Febbraio 2012, 12:42:09 CET »
0
Salve, devo effettuare una connessione al WebServer utilizzando Ksoap2.

Al momento non utilizzo KSOAP2, ma mi limito ad inviare l'XML richiesto dal WebServer per effettuare l'operazione di Login.


Codice (XML): [Seleziona]
package connessioni;
import java.net.*;
import java.io.*;


public class login {
         

public static void main (String args[]) {
       
         try {
              String xmldata =
            "<?xml version=\"1.0\" encoding=\"utf-8\"?>"+
            "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"+
            "<soap:Header>"+
              "<WsAuthentication xmlns=\"[url=http://tempuri.org/\">"]tempuri - Bing[/url]+
                "<Username>xxxxxxxx</Username>"+
                "<Password>xxxxxxxxx</Password>"+
              "</WsAuthentication>"+
            "</soap:Header>"+
            "<soap:Body>"+
              "<Login xmlns=\"[url=http://tempuri.org/\">"]tempuri - Bing[/url]+
                "<user>yyyyyyyyyyyyy</user>"+
            "<password>yyyyyyyyyyyy</password>"+
            "</Login>"+
            "</soap:Body>"+
            "</soap:Envelope>";
                               
              //Create socket
              String hostname = "95.110.225.205";
              int port = 80;
              InetAddress  addr = InetAddress.getByName(hostname);
              Socket sock = new Socket(addr, port);
                               
              //Send header
              String path = "/wsscontisubito/wsUtente.asmx?op=Login";
              BufferedWriter  wr = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(),"UTF-8"));
              // You can use "UTF8" for compatibility with the Microsoft virtual machine.
              wr.write("POST " + path + " HTTP/1.0\r\n");
              wr.write("Host: 95.110.225.205\r\n");
              wr.write("Content-Length: " + xmldata.length() + "\r\n");
              wr.write("Content-Type: text/xml; charset=\"utf-8\"\r\n");
              wr.write("\r\n");
                               
              //Send data
              wr.write(xmldata);
              wr.flush();
                               
              // Response
              BufferedReader rd = new BufferedReader(new InputStreamReader(sock.getInputStream()));
              String line;
              while((line = rd.readLine()) != null)
                System.out.println(line);
            } catch (Exception e) {
              e.printStackTrace();
            }
       
       
}
}

Chi mi aiuta ad effettuare la modifica?

Grazie

Del lato server, non ho il WSDL, ma questo:

Codice (XML): [Seleziona]
POST /wsscontisubito/wsUtente.asmx HTTP/1.1
Host: 95.110.225.205
Content-Type: text/xml; charset=utf-8
Content-Length:length
SOAPAction: "[url=http://tempuri.org/Login"]tempuri - Bing[/url]

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <WsAuthentication xmlns="[url=http://tempuri.org/">]tempuri - Bing[/url]
      <Username>string</Username>
      <Password>string</Password>
    </WsAuthentication>
  </soap:Header>
  <soap:Body>
    <Login xmlns="[url=http://tempuri.org/">]tempuri - Bing[/url]
      <user>[color=blue]string[/color]</user>
      <password>[color=blue]string[/color]</password>
    </Login>
  </soap:Body>
</soap:Envelope>

In risposta avrò:

Codice (XML): [Seleziona]
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <WsAuthentication xmlns="[url=http://tempuri.org/">]tempuri - Bing[/url]
      <Username>string</Username>
      <Password>string</Password>
    </WsAuthentication>
  </soap:Header>
  <soap:Body>
    <LoginResponse xmlns="[url=http://tempuri.org/">]tempuri - Bing[/url]
      <LoginResult>string</LoginResult>
    </LoginResponse>
  </soap:Body>
</soap:Envelope>
« Ultima modifica: 29 Febbraio 2012, 16:52:05 CET da cretara »

Offline cretara

  • Nuovo arrivato
  • *
  • Post: 9
  • Respect: +1
    • Mostra profilo
  • Dispositivo Android:
    Virtual devices
  • Sistema operativo:
    windows7
Re:SOAP Vs KSOAP2
« Risposta #1 il: 29 Febbraio 2012, 16:58:02 CET »
0
Ho provato così, ma non va:

Codice (Java): [Seleziona]
package connessioni;
import java.net.*;
import java.io.*;
import org.ksoap2.*;

import org.ksoap2.serialization.*;
import org.ksoap2.transport.*;


public class login {
 
       

public static void main (String args[]) {
         String SOAP_ACTION = "[url=http://tempuri.org/Login";]tempuri - Bing[/url]
     String METHOD_NAME = "Login";
         String NAMESPACE = "http://tempuri.org";
         String URL = "http://95.110.225.205/wsscontisubito/wsUtente.asmx";
    try {
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty("Username", "xxxxxxx");
        request.addProperty("Password", "xxxxxxxxx");
        request.addProperty("user", "yyyyyyyyy");
        request.addProperty("password", "yyyyyyyyy");
 
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.call(SOAP_ACTION, envelope);
 
        Object result = envelope.getResponse();
 
        //handle result here
 
     //   myExampleHandler.getResults();
    } catch (Exception e) {
        e.printStackTrace();
    }


       
}
}

L'errore che ottengo è il seguente:

Codice: [Seleziona]
java.lang.RuntimeException: unexpected tag:details
        at org.ksoap2.SoapFault.parse(Unknown Source)
        at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(Unknown Source)
        at org.ksoap2.SoapEnvelope.parse(Unknown Source)
        at org.ksoap2.transport.Transport.parseResponse(Unknown Source)
        at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:100)
        at connessioni.login.main(login.java:32)


Come funziona il metodo addProperty()? Cosa devo passargli?
Quali sono i campi da aggiungere oltre ad Username, Password, user, password?
Il lenght devo passarlo?