PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV Mobile 2024 → SOAP WS-Security
SOAP WS-Security
Débuté par HIS 21, 07 juil. 2016 11:24 - 4 réponses
Posté le 07 juillet 2016 - 11:24
Good morning,

I have imported a web service into my project by using its WSDL. Now the problem is that this web service uses the SOAP WS-Swcurity extension and I don't know how WM implements this feature (I hope it is implemented in WM but, by what I'm reading, I'm worried because it seems that WM does not allow to use WS-Sweurity natively).

Can somebody help me to find a way to use WS-Security in WM?

I also have a problem by using an external Java library to solve the WS-Security problem:
When I import the Ksoap java library as jar file into my apk file and I generate the application WM tells me something like "there is a problem with an object that is already included in the apk" (or something similar).

Is WM using the Ksoap library due to fact that I have already used a web service in my project with the native implementation of WM? (I have to use many web services in my project then I have included the Ksoap library and the "native" mamagement of web services provided by WM in this project).

Thanks for help.
Membre enregistré
3 659 messages
Popularité : +175 (223 votes)
Posté le 07 juillet 2016 - 20:22
Hi His,

I opened a call on the matter, also'm with this demand!

:thank you:

--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 9949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Posté le 12 juillet 2016 - 16:55
Hi,

after a long work (at the end of which I have decompiled the generated apk by WM) I've found the problem, it was very hard to discover:

as I supposed initially the problem was that also WM was using internally the Ksoap library.

Now I'm working to rename the Java package of Ksoap, to recreate the package and to re-import it on my WM project.
Membre enregistré
3 659 messages
Popularité : +175 (223 votes)
Posté le 12 juillet 2016 - 18:26
Utilizando WebServices no Android com KSOAP
Paulo Henrique Nery Oliveira / 30 de outubro de 2015

Existem várias maneiras de realizar a comunicação remota de aplicativos Android com servidores para hospedagem de dados. Pode ser com um servidor PHP utilizando metodos GET e POST, JSON, XML, etc. Particularmente gosto de utilizar Web Services para fazer o tráfego dos dados das minhas aplicações, pois posso passar os objetos pelo web service sem consumir banda de internet com dados “desnecessários” como o XML.

O primeiro passo para implementar um cliente webservice no Android é baixar a biblioteca KSOAP 2 em http://code.google.com/p/ksoap2-android/

O segundo passo é adicionar essa biblioteca ao projeto que se está trabalhando, caso não saiba como fazer, veja esse tutorial. Agora para fazer a comunicação entre seu aplicativo Android e seu webservice é bem simples.

Essa é a classe cliente do Web Service, para comunicação e recebimento dos dados:

PUBLIC class WebServiceCliente {
PRIVATE static final string NAMESPACE = "http://webservice.henriquelacerda.com.br/";
PRIVATE static final string METHOD_NAME_BUSCAR_CLIENTES = "buscarCliente";
PRIVATE static final string SOAP_ACTION = "";
PRIVATE static string URL = "http://www.webservice.henriquelacerda.com.br:8080/webService?wsdl";
PUBLIC WebServiceCliente() { }
PUBLIC List buscarClientes() {
List clientes = new LinkedList();
// Aqui criamos a requisicao
SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME_BUSCAR_CLIENTES);
// Aqui criamos o envelope que será enviado
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
// Realizamos a chamada do webservice
androidHttpTransport.call(SOAP_ACTION, envelope);
// Recebemos o retorno, convertendo em SoapObject
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
int propsNum = resultsRequestSOAP.getPropertyCount();
// Iteração para "ler" os objetos recebidos
for (int i = 0; i < propsNum; i++) {
SoapObject element = (SoapObject) resultsRequestSOAP.getProperty(i);
clientes.add(element.getProperty("cliente").toString());
}
} catch (EXCEPTION e) {
System.out.println(e.toString());
}
RETURN clientes;
}
}


É um exemplo simples de comunicação de dados, nesse caso estamos trabalhando apenas com Strings mas funciona perfeitamente com Objetos do Java.
Para enviar dados para o Web Service devemos utilizar o Objeto PropertyInfo que é enviado na requisição pelo objeto SoapObject, assim podemos passar parametros no método que iremos utilizar do Web Service.

SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME_BUSCAR_CLIENTES);
PropertyInfo propInfo = new PropertyInfo();
propInfo.name = "id_empresa";
propInfo.type = PropertyInfo.STRING_CLASS;
request.addProperty(propInfo, _configuracao.getCodigoEmpresa());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.implicitTypes = True;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);


Existem bem mais coisas possíveis de se fazer, mas abordei aqui o básico, se houver interesse posso abordar as coisas mais complexas que abrangem o uso de Web Services.

--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 9949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Posté le 14 juillet 2016 - 16:45
Hi everybody,

at the end I've solved by renaming the Ksoap pachages from

org.kobjects.*
org.ksoap2.*
org.kxml2.*
xmlpull.*

to

cutrom.kobjects.*
etc etc...

after that I've rebuilt the jar archive and I've reimported it on my project.

All worked fine.