|
- Overview
- Importing a Webservice into a project
- Import
- "Project explorer" pane: viewing a webservice
- Description and properties of a Webservice
- Updating the description of a Webservice
- Properties of a Webservice modifiable in the editor
- Using a Webservice
- Principle
- Properties associated with the Webservice
- Properties available on the types of variables
- Advanced operations of the XML stream of the Webservice
- Special case: the Webservice returns a result whose type is not recognized by WINDEV, WEBDEV and WINDEV Mobile
- Distributing a WINDEV application that is using a Webservice
Importing/Consuming Webservices
WINDEV, WEBDEV and WINDEV Mobile allow you to directly import Webservices into your applications. A Webservice is a set of entry points made available to the users in order to perform different processes. For example, a service for remote access provides the processes used to access the data. The exchanges of information with a Webservice are performed in XML format and they use the SOAP (Simple Object Access Protocol) and HTTP protocols. From the description in WSDL format (Web Services Description Language) of this service, WINDEV, WEBDEV or WINDEV Mobile will automatically generate the WLanguage types and functions corresponding to the programming interface of Webservice. Remark: For backward compatibility with the earlier versions, you can also ask to generate a set of procedures or a class whose methods correspond to the Webservice operations. However, we recommend you that use the new mechanism for automatically generation of native types. To use the Webservice, all you have to do is use the functions generated during the import. This help page presents: Versions 17 and later New in version 17 Versions 18 and later New in version 18 Importing a Webservice into a project Import To import a Webservice: - Select the "Workshop .. Webservices (SOAP, .Net, J2EE) .. Import and use a Webservice in this project" option. The wizard for importing a Webservice starts.On the "Project" pane, in the "Project" group, expand "Import" and select "A Webservice (Soap, .Net, J2EE)". The wizard for importing a Webservice starts.On the "Project" pane, in the "Project" group, expand "Import" and select "A Webservice (Soap, .Net, J2EE)". The wizard for importing a Webservice starts.On the "Project" pane, in the "Project" group, expand "Import" and select "A Webservice". The wizard for importing a Webservice starts.
- In the wizard, the presentation screen is displayed. Go to the next step.
- Specify the location of the WSDL. This file corresponds to the webservice description. It contains the description of each function found in the Webservice as well as their parameters. Two methods can be used to locate the WSDL:
- from a URL, HTTP address where the WSDL is found.
Remarks: - You have the ability to specify the user name and the password if an authentication is required.
Versions 22 and laterThe "Proxy" button is used to configure the proxy options if necessary. New in version 22The "Proxy" button is used to configure the proxy options if necessary. The "Proxy" button is used to configure the proxy options if necessary.
- from an XML file found on the current computer.
Remark: We do not advise you to check "Import in mode compatible with version 14". In this case, the management of the calls to the Webservice is more complex and the new types are not supported (arrays, structure, etc.). See Importing Webservices in compatible mode for more details. - Validate the wizard. A message is displayed, indicating that the import is ended.
- The Webservice is automatically added into the "Project explorer" pane (in the "Webservices" branch). It is ready to use.
"Project explorer" pane: viewing a webservice The imported Webservice is in the "Webservices" folder of the "Project explorer" pane: The structure includes: - the name of the Webservice.
- the name of each function.
- the name of a structure containing either the call parameters, or the return values.
- the name of each variable in the structure.
Description and properties of a Webservice Updating the description of a Webservice When a Webservice evolves (corrections, new versions, etc.), its description may also evolve. To update the description of a Webservice in your project: - Select the Webservice in the "Project explorer" pane.
- Select "Update" from the popup menu.
Remark: The Webservices imported by using the compatibility mechanism with the earlier versions cannot be updated. Properties of a Webservice modifiable in the editor To modify the properties of a Webservice in the editor: - Select the Webservice in the "Project explorer" pane.
- Select "Description" from the popup menu.
- The window of properties is displayed. The following properties can be modified in this window:
- The import address of Webservice: it is the URL used to reach the WSDL describing the Webservice.
- The user name and the password used to import the WSDL.
Principle To use a Webservice, you must: - Declare 2 variables: a variable used to specify the call parameters and a variable used to retrieve the response.
- Initialize each variable of the call structure.
- Call the Webservice function by passing the call variable in parameter and retrieve the response variable in return.
Example:
trackingSearch is trackSearch trackingSearchRes is resultTrackSearch trackingSearch.accountNumber = 99999999 trackingSearch.consigneesCountry = "FR" trackingSearch.consigneesZipCode = "37100" trackingSearch.sendersRef = "111111" trackingSearchRes = TrackingServiceWSService.trackSearch(trackingSearch) IF ErrorOccurred() THEN Trace("Failed to call the Webservice: " + ErrorInfo(errFullDetails)) ELSE Trace("Webservice successfully run") END
In most cases, the result returned by the Webservice is in XML format. Therefore, the XML functions must be used to decode the response. Properties associated with the Webservice To handle a Webservice by programming, simply use the name of the Webservice (found in the "Project explorer" pane). Remark: You can drag and drop directly from the "Project explorer" pane to the code editor to insert the name of the Webservice. The following properties can be modified by programming: | | | Name | Type used | Effect |
---|
Address | Character string | Used to replace the call address of Webservice described in the WSDL by another URL. This property is useful if the Webservice is hosted on different servers. This property has the following format: "http://server:port/webservice_path". For a Webservice generated with WINDEV and deployed on a WEBDEV Application Server, it is the URL of the file whose extension is "awws". Remarks: - The modification of this property replaces all the URLs described in the WSDL.
- If this property corresponds to an empty string (""), the URLs described in the WSDL will be re-used.
| | Integer constant | Used to force the HTTP authentication method: - auAutomatic (default value): automatic authentication method.
- auBasic: Basic authentication method.
- auNegotiate: Negotiate authentication method.
| IgnoreError | Combination of constants | Used to ignore the certificate errors. the following constants can be used:- httpIgnoreInvalidCertificate: Used to ignore an invalid certificate or a certificate coming from an unknown company.
- httpIgnoreInvalidCertificateName: Used to ignore the name of the site found in the certificate.
- httpIgnoreExpiredCertificate: Used to ignore the date of the certificate.
- httpIgnoreRedirectToHTTP: Used to redirect to a non-secure server.
- httpIgnoreRedirectToHTTPS: Used to redirect to a secure server.
- httpIgnoreRevocation: Used to ignore the check in the list of revoked certificates.
Remarks: The errors regarding the security of transactions are ignored. IgnoreError is not available. Before version 200057, the errors regarding the security of transactions were ignored. IgnoreError was not available. From version 200057, the following errors are supported: httpIgnoreExpiredCertificate, httpIgnoreInvalidCertificate, httpIgnoreInvalidCertificateName, httpIgnoreRevocation. The other errors are ignored. For backward compatibility, all the errors are ignored by default.
| Versions 18 and laterMethodHTTP New in version 18MethodHTTP MethodHTTP | Integer constant | HTTP method used to call the Webservice:- httpPost (default value): POST method
- httpPut: PUT method
| Port | Character string | Name of the port defined in the WSDL. It is the port used to communicate with the server that is hosting the Webservice. See your network manager or the owner of the Webservice. | User | Character string | User name that will be used to perform the authentication during the HTTP requests to the Webservice. This name is used only if an authentication is required to access the server on which the Webservice is hosted. With the Negotiate authentication method, the domain must be added to the user depending on the configuration:
myWebservice..User = "DOMAIN\User"
or
myWebservice..User = "User@DOMAIN"
| Password | Character string | Password used to perform the authentication during the HTTP requests to the Webservice. This name is used only if an authentication is required to access the server on which the Webservice is hosted. | Note: - If a user name and a password are specified, the authentication of the HTTP requests will be done by using the "Basic" authentication schema, in which the parameters are in clear in the HTTP request. We recommend that you use HTTPS requests if the authentication is required.
- If the server that hosts the Webservice requires a Windows authentication in HTTP, HTTPParameter must be called before consuming the Webservice (in order for Internet Explorer to be used for the HTTP requests).
Caution: The properties modifiable in the editor and the properties modifiable by programming have no link. Properties available on the types of variables The types of variables automatically declared when importing the WSDL propose several properties: | | | Name | Type used | Effect |
---|
Exist | Boolean | - True if the type of variable exists in the Webservice response,
- False otherwise.
| Occurrence | Integer | Number of elements of this type in the response of the Webservice. A Webservice can return arrays of variables. ..Occurrence is used to find out the size of returned array and the [ ] operator is used to access the array elements. | Type | Character string | Name of the variable type. This property is used when a Webservice is likely to return responses of different types. | Value | Variant | Value of variable. Remark: This property is accessed by default when only the variable name is used. For example:
myWebservice.RequestVariable = EDT_Value
is equivalent to:
myWebservice.RequestVariable..Value = EDT_Value
|
Advanced operations of the XML stream of the Webservice In some cases, you may have to handle the XML data stream exchanged with the Webservice. Some Webservices ask for example to add headers into their XML stream to allow the authentication or return meta information in the response headers. The following functions can be used to respond to these particular requests: | | SOAPPrepare | Builds the request to the Webservice for a given function and parameters but it does not send it. | SOAPAddHeader | Adds custom headers into a call to a Webservice. | SOAPGetHeader | Re-reads the information found in the header of the Webservice response. | SOAPAddAttribute | Declares the additional attributes (not found in the WSDL) on a Webservice variable automatically generated. It is used in advanced programming when the WSDL returned by the Webservice does not exactly correspond to the expected type. |
Special case: the Webservice returns a result whose type is not recognized by WINDEV, WEBDEV and WINDEV Mobile The types of variables available in WINDEV and the ones available in a SOAP Webservice can differ. The simple types (boolean, integer, etc.) and the complex types (datetime, duration, structures, arrays of simple types and array of structures, nested structures, etc.) used in the Webservice are automatically converted into the WLanguage format (and conversely) when the service is imported into a project. The Array types are also supported. The most evolved types (classes, advanced types of WLanguage, etc.) are processed as character strings in the WLanguage code. These character strings contain the XML code corresponding to the type of variable returned by the Webservice and to its content. Therefore, if a Webservice returns a result as a class instance, this result will be processed in the procedure as a character string in XML format. Then, you will have to process this character string (in WLanguage) in order to extract the requested information. See the XML functions for more details. Remarks: - If the Webservice returns a structure, the name of the members found in the return structure is case sensitive.
- If you are using a structure in parameter of a Webservice function and if a DATE member is not assigned, the following error will be displayed: "The 0000-00-00 value does not respect the XSD schema".
Distributing a WINDEV application that is using a Webservice To distribute an application that is using a Webservice, all you have to do is include the file describing the Webservice (.wsdl file) in the library of the application. In order for the application to be able to run the Webservice, the end-user computers must have an access to Internet. Remark: Before distributing an application that is using a Webservice, we recommend that you check the license and the distribution rights of this service (in case there is a free for the service).
Related Examples:
|
Training (WINDEV): WD Webservice Client
[ + ] This example illustrates the use of WebServices. It explains how to retrieve, from a WebService, images according to keywords. This project is the client that connects to the "WD Webservice Server" WebService.
|
|
Training (WINDEV): WD Webservice Server
[ + ] This example illustrates the use of the WebServices. It explains how to create a WebService by providing some images according to keywords. This project is the WebService that is used th the WD Webservice Client project.
|
This page is also available for…
|
|
|
| |
| Alterando o endereço do Webservice |
|
| localurl is boolean//
IF localurl = False THEN WebserviceJson..Address = "http://DESKTOP-C6804SU/WEBSERVICESOAP_WEB/awws/WebserviceJson.awws" ELSE WebserviceJson..Address = "http://200.203.134.1/WEBSERVICESOAP_WEB/awws/WebserviceJson.awws" END
varx is string = WebserviceJson..Address
envio01 is a ws_select_clientesResponse //inicia o metodo
envio01 = ws_select_clientes("Adriano") //passagem de parametros
sResultado is string = envio01.ws_select_clientesResult // pegando o resultado
stArrClientes is Structure clientesID is 8-bytes int nome is string telefone is string status is boolean avatar is string token is string END
arrClientes is array of stArrClientes
arrClientes = JSONToVariant(sResultado)
FOR EACH stcliente OF arrClientes TableAdd(TABLE_Clientes,stcliente.nome +TAB+ stcliente.telefone +TAB+ stcliente.status) END
|
|
|
|
| |
| |
| |
|
| Consumir WebService - Cotação Dolar |
|
| //Buscar em Json // http://api.promasters.net.br/cotacao/ s_url is string="http://api.promasters.net.br/cotacao/v1/valores" IF HTTPRequest(s_url) THEN SAI_Resultado= HTTPGetResult() END let jz=JSONToVariant(SAI_Resultado) TableDeleteAll(TABLE_indices) FOR EACH _m OF jz..Member TableAddLine(TABLE_indices,_m..Name+TAB+" = "+_m..Value) TableAddLine(TABLE_indices,"=========================") mebros(_m) END INTERNAL PROCEDURE mebros(x) FOR EACH _m2 OF x..Member TableAddLine(TABLE_indices,_m2.nome,_m2.valor,_m2.fonte,_m2.ultima_consulta) END END
//
//Buscal em Xml s_url is string="http://api.promasters.net.br/cotacao/v1/valores?alt=xml" IF HTTPRequest(s_url) THEN SAI_Resultado= HTTPGetResult() END TableDeleteAll(TABLE_indices) // Elimina Dados da Tabela XMLDocument("XML1",SAI_Resultado) _status is string=XMLRead("XML1","/Root/status") TableAddLine(TABLE_indices,"Status",_status) s_nome is string="" s_valor is string="" s_fonte is string="" s_ultima_consulta is string="" s_nome_tag is string="" XMLFind("XML1",Null,XMLElément+XMLChildItem,XMLStartWith) WHILE XMLFound("XML1") //Percorrer xml SWITCH XMLElementType("XML1") CASE XMLTag : s_nome_tag = XMLElementName("XML1") // vou pegar nome da tag IF s_nome_tag="nome" THEN s_nome=XMLData("XML1") IF s_nome_tag="valor" THEN s_valor=XMLData("XML1") IF s_nome_tag="ultima_consulta" THEN s_ultima_consulta=XMLData("XML1") IF s_nome_tag="fonte" THEN s_fonte=XMLData("XML1") END IF s_fonte<>"" THEN TableAddLine(TABLE_indices,s_nome,s_valor,s_fonte,s_ultima_consulta) s_nome="" s_valor="" s_fonte="" s_ultima_consulta="" END XMLNext("XML1") END XMLClose("XML1") //Fim Buscal em Xml
// Blog com Video E Exemplo
http://windevdesenvolvimento.blogspot.com.br/2017/02/aula-1055-webservice-007-consumir.html
https://www.youtube.com/watch?v=YbQPRcX5iVE
|
|
|
|
| |
| |
| |
|
| Consumir WebService - Cnpj Receita |
|
| //Retorno Json { "atividade_principal": [ { "text": "Desenvolvimento e licenciamento de programas de computador customizáveis", "code": "62.02-3-00" } ], "data_situacao": "03/11/2005", "complemento": "SALA 15", "nome": "MATOS INFORMATICA - EIRELI - EPP", "uf": "RS", "telefone": "(51) 3595-1132 / (51) 3595-2474", "atividades_secundarias": [ { "text": "Desenvolvimento e licenciamento de programas de computador não-customizáveis", "code": "62.03-1-00" } ], "qsa": [ { "qual": "65-Titular Pessoa FÃsica Residente ou Domiciliado no Brasil", "nome": "AMARILDO DE MATOS" } ], "situacao": "ATIVA", "bairro": "PATRIA NOVA", "logradouro": "R PARAIBA", "numero": "198", "cep": "93.410-130", "municipio": "NOVO HAMBURGO", "abertura": "23/05/1989", "natureza_juridica": "230-5 - Empresa Individual de Responsabilidade Limitada (de Natureza Empresária)", "cnpj": "92.715.978/0001-58", "ultima_atualizacao": "2017-01-04T22:35:08.977Z", "status": "OK", "tipo": "MATRIZ", "fantasia": "", "email": "", "efr": "", "motivo_situacao": "", "situacao_especial": "", "data_situacao_especial": "", "capital_social": "100000.00", "extra": {} } // //Buscar em Json // https://www.receitaws.com.br/v1/cnpj/NumeroCnpj //https://www.receitaws.com.br/v1/cnpj/92715978000158 s_url is string="https://www.receitaws.com.br/v1/cnpj/"+SAI_Cnpj IF HTTPRequest(s_url) THEN SAI_resultado= HTTPGetResult() //Vai retornar os dados do cnpj em Json END
_dados_atividade is Structure text is string code is string FIN _dados_qsa is Structure qual is string nome is string FIN _dados_cnpj is Structure atividade_principal is array of _dados_atividade atividades_secundarias is array of _dados_atividade qsa is array of _dados_qsa data_situacao is string complemento is string nome is string uf is string telefone is string situacao is string bairro is string logradouro is string numero is string cep is string municipio is string abertura is string natureza_juridica is string cnpj is string ultima_atualizacao is string status is string tipo is string fantasia is string email is string efr is string motivo_situacao is string situacao_especial is string data_situacao_especial is string capital_social is string END _estrutura_dados_cnpj is _dados_cnpj Deserialize(_estrutura_dados_cnpj,SAI_resultado,psdJSON)
FOR EACH _atividade OF _estrutura_dados_cnpj.atividade_principal Info(_atividade.text+CR+_atividade.code) END FOR EACH _atividade_secundaria OF _estrutura_dados_cnpj.atividades_secundarias Info(_atividade_secundaria.text+CR+_atividade_secundaria.code) END FOR EACH _dados_qsa OF _estrutura_dados_cnpj.qsa Info(_dados_qsa.qual+CR+_dados_qsa.nome) END Info(_estrutura_dados_cnpj.nome+CR+... _estrutura_dados_cnpj.data_situacao+CR+... _estrutura_dados_cnpj.complemento+CR+... _estrutura_dados_cnpj.nome+CR+... _estrutura_dados_cnpj.uf+CR+... _estrutura_dados_cnpj.telefone+CR+... _estrutura_dados_cnpj.situacao+CR+... _estrutura_dados_cnpj.bairro+CR+... _estrutura_dados_cnpj.logradouro+CR+... _estrutura_dados_cnpj.numero+CR+... _estrutura_dados_cnpj.cep+CR+... _estrutura_dados_cnpj.municipio+CR+... _estrutura_dados_cnpj.abertura+CR+... _estrutura_dados_cnpj.natureza_juridica+CR+... _estrutura_dados_cnpj.cnpj+CR+... _estrutura_dados_cnpj.ultima_atualizacao+CR+... _estrutura_dados_cnpj.status+CR+... _estrutura_dados_cnpj.tipo+CR+... _estrutura_dados_cnpj.fantasia+CR+... _estrutura_dados_cnpj.email+CR+... _estrutura_dados_cnpj.efr+CR+... _estrutura_dados_cnpj.capital_social)
// Blog com Video e Exemplo
http://windevdesenvolvimento.blogspot.com.br/2017/02/aula-1056-webservice-008-consumir.html
https://www.youtube.com/watch?v=F16h1Z3Lm-c
https://www.youtube.com/watch?v=aIdnH82ru_4
|
|
|
|
| |
| |
| |
|
| | //Buscar Cep WebService
_url is string="http://correiosapi.apphb.com/cep/"+EDT_cep solicitacao is a httpRequest //Inicia uma solicitacao HTTP em um Servidor. resposta is a httpResponse // Recuperar a resposta do httprequest solicitacao..URL=_url solicitacao..Method=httpGet resposta=RESTSend(solicitacao) // Envia uma solicitação e aguarda a resposta do servidor IF resposta..StatusCode=200 THEN ELSE Info(resposta..StatusCode+CR+resposta..DescriptionStatusCode) END retorno is ANSI string=UTF8ToString(resposta..Content) SAI_TextoJson=Utilitarios_matos_wdk.remove_acento_util_wdk(retorno) // Estou colocando retorno no meu texto Json _cep_ is Structure cep is string tipoDeLogradouro is string logradouro is string bairro is string cidade is string estado is string END //Criando uma Estrutura Cep Estrutura_json is _cep_ Deserialize(Estrutura_json,SAI_TextoJson,psdJSON) EDT_rua=Estrutura_json.logradouro EDT_bairro=Estrutura_json.bairro EDT_Cidade=Estrutura_json.cidade EDT_Estado=Estrutura_json.estado EDT_TipodeLogradouro=Estrutura_json.tipoDeLogradouro
//{"cep":"93410130","tipoDeLogradouro":"Rua","logradouro":"Paraíba", //"bairro":"Pátria Nova","cidade":"Novo Hamburgo","estado":"RS"} //200: solicitacao processada com êxito //301: documento movido permanentemente //302: Documento mudou temporariamente //403: O servidor entendeu o pedido, mas recusa-se a executá-lo. //404: não encontrado //500: erro interno do servidor //503: Serviço temporariamente indisponível ou manutenção
// Blog com Video E Exemplo
http://windevdesenvolvimento.blogspot.com.br/2017/02/aula-1058-windev-webservice-010-buscar.html
https://www.youtube.com/watch?v=eOnNOAHIBa4 |
|
|
|
| |
| |
| |
|
| | http://forum.pcsoft.fr/fr-FR/pcsoft.br.windev/546-webdev-webservice-funcoes-internas-para-auxilizar-criacao-xml/read.awp
http://forum.pcsoft.fr/fr-FR/pcsoft.br.windev/443-was-webdev-aplicativo-server-494/read.awp
|
|
|
|
| |
| |
| |
| |
| |
| |
| | |
| |