46
DFG Web Services - Implementation of Web Service Client Applications | Gipuzkoa.net |Department for the Arrangement and Territorial Promotion DFG Web Services Implementation of Web Service Client Applications Territory Planning Service Gipuzkoa Provincial Council February 2007

DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

DFG Web Services Implementation of Web Service

Client Applications Territory Planning Service

Gipuzkoa Provincial Council February 2007

Page 2: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Contents

1. Description of the Document

2. .Net client application package

2.1. Introduction

2.2. Creating a consumer application package for the 'Localizar por ID' web service

2.2.1. Add controls to the application package

2.2.2. C# Code

2.2.3. Test the Example

2.2.4. Expand the Example

2.2.5. Test the Extended example

3. Java client application package

3.1. Introduction

3.2. Requirements

3.3. Processes to be implemented

3.4. Source Code

Page 3: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

3.4.1. WSExecutor.java

4. Web client

5. PHP client application package

5.1. Introduction

5.2. Requirements

5.3. Source Code

6. PDA Windows Mobile Application Package

6.1. Introduction

6.2. Creating the PDA project

6.3. Creating a consumer application package for the DibujarImagen' web service

6.3.1. Añadir controles al aplicativo

6.3.2. Source Code

6.3.3. Test the example with the emulator

Page 4: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

1 - Description of the Document This document describes the prototypes of Web Service consumer applications

packages developed as integration examples of the Spatial Web Services in the

current version of the platform.

It describes the implemented prototypes and acts as a manual to develop other

client applications packages in different development platforms.

It describes four client applications package prototypes in four different

technologies, that demonstrate the interoperability of the Web Services.

The four technologies that implemented the prototypes are: .Net, Java, a Web

client and php.

There is a prototype developed in .Net which implements the use of the whole

functionality served by the different web services of the Platform (See

http://b5m.gipuzkoa.net/appws/publish.htm ). Due to its complexity, a reduced

prototype is described in this document.

2 - .Net client application package

2.1 - Introduction

The development of the client in Microsoft .Net platform has been performed with

the Visual Studio 2005 development environment and the C# programming

language. The described prototype accesses to the Localizar por ID web service.

Page 5: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

2.2 - Creating a consumer application package for the

'Localizar por ID' web service

Select “Add New Data Source” option from the Data menu.

The first window of the Wizard will appear.

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Page 6: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

Select the “Web Service” option and the “Next” button and the following web

reference window will appear.

In the URL text box, enter the URl of the WSDL file for the web service that tallies

with the web service to be used.

Example: Localizar por Id.

http://b5m.gipuzkoa.net/dfg-localizar-context-

root/LocalizarPorIdSoapHttpPort?WSDL

After a few seconds, a list of the methods that the service has available will appear.

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Page 7: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

Select the “Add Reference” and the following window appears.

When you select "Finish", the Wizard window closes and the new reference is added

to the solution and the "Data Source" creates.

The new web reference will appear in the “Solution Explorer” window.

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Page 8: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

When you select the “Data->Show Data Sources” option from the menu, the Data

Sources window will appear.

A Data Source appears for each output variable of the Web Services that can be

opened to explore the data structure.

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Page 9: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

2.2.1 - Add controls to the application package

In order to view the Web Service response, a DataGrid can be added by dragging

the icon from the Data Source to the form. In the example, the

“LocalizarPorIdUser_localizaridcallejero_Out -> objectOut ->listaDirecciones ”

structure is dragged from the service to the form.

A Button type control is added to call the Web Service.

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Page 10: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

2.2.2 - Código C#

The access code to the Web Service is added to the “button1_Click” method.

Double clicking on the design mode button creates the empty class in codification

mode.

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { } } }

Page 11: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

Add the following the code lines to the button1_Click() method.

private void button1_Click(object sender, EventArgs e) { // Crear una nueva instancia de la clase del Web Service. net.gipuzkoa.b5m.LocalizarPorId webId = new net.gipuzkoa.b5m.LocalizarPorId(); // Array de capa adicionales a nulo. net.gipuzkoa.b5m.WsmapasselectUser[] nomArr = null; // Llama al Web Service y recoger la respuesta. net.gipuzkoa.b5m.LocalizarPorIdUser_localizaridcallejero_Out webIdOut=webId.localizaridcallejero("D_4545","","0","Si", "PUBLI", "200", "200", "NO", nomArr); // Asignar la respuesta al DataSource. listaDireccionesBindingSource.DataSource = webIdOut.objectOut.listaDirecciones; }

2.2.3 - Test the Example

Run the application, select the button to launch the request to the Web Service and

after a few seconds, the service response will appear in the Grid.

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Page 12: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

2.2.4 - Expand the Example With the Imagen=”Si” parameter, the service has generated an image that tallies

with the Id "D-4545" that has been used. In this section, the example will be

expanded to draw the image.

You first have to the form in design mode and add a PictureBox that is used to

display the map and a TextBox to introduce the identifier of the building.

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Page 13: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

The modified method to process the image will then appear. The code has also

been modified to clear the image and the DataSource and the status of the cursor is

updated while the service is executed.

private void button1_Click(object sender, EventArgs e) { // Cambiar el cursor. Cursor.Current = Cursors.WaitCursor; // Limpiar el DataSource listaDireccionesBindingSource.Clear(); // Limpiar la imagen. if (pictureBox1.Image != null) pictureBox1.Image = null; Refresh(); // Crear una nueva instancia de la clase del Web Service. net.gipuzkoa.b5m.LocalizarPorId webId = new net.gipuzkoa.b5m.LocalizarPorId(); // Array de capa adicionales a nulo. net.gipuzkoa.b5m.WsmapasselectUser[] nomArr = null; // Llama al Web Service y recoger la respuesta. net.gipuzkoa.b5m.LocalizarPorIdUser_localizaridcallejero_Out webIdOut = webId.localizaridcallejero (richTextBox1.Text, "", "0", "Si", "VITO", pictureBox1.Width.ToString(), pictureBox1.Height.ToString(), "NO", nomArr); // Asignar la respuesta al DataSource. listaDireccionesBindingSource.DataSource = webIdOut.objectOut.listaDirecciones; // Recoger el URL de la imagen string IdCallUrl = Convert.ToString(webIdOut.imagenurlOut); // Pedir y dibujar el mapa if (webIdOut.imagenurlOut != null) { WebRequest WReq = WebRequest.Create(IdCallUrl); WebResponse WRes = WReq.GetResponse(); Stream strm = WRes.GetResponseStream(); Image WImage = Image.FromStream(strm); pictureBox1.Image = WImage; } // Dejar el default cursor. Cursor.Current = Cursors.Default; }

Page 14: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

In addition, the following namespaces to the project have to be added.

using System.Net; using System.IO;

2.2.5 - Test the Extended example

Run the new version of the example and the map will appear focused on the

building that tallies with the ID.

When the ID is changed and the service launched, the data of the previous request

is deleted. The data and image of the new request will appear after a few seconds.

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Page 15: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

3. - Java client application package

3.1 - Introduction

In this case, the implementation in Java is described of a client that uses a web

service also using the WSDL description archive

3.2 – Requirements

The ECLIPSE WTP PROJECT software is used to generate client classes using the

WSDL description archive. This software may be downloaded from:

http://www.eclipse.org/webtools/main.html

The above project includes all the necessary plugins and the Eclipse platform. The

JVM required is 1.5.

http://java.sun.com/j2se/1.5.0/download.jsp

In both cases, the installation instructions described in the given URLs have to be

followed.

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Page 16: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

3.3 - Processes to be implemented

Once it is installed, the J2EE perspective is accessed from the Eclipse platform:

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Page 17: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

A new project is created in the following file: Dynamic Web Projets

In this case DFGWeb and we put the wsdl description file in the WSDL directory.

Once selected using the right button as is shown in the figure, the following classes

are generated:

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Page 18: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

The process generates the necessary classes to check the service, as well as

registering jsp pages to be checked in the servers.

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Page 19: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

A Java project is generated to check the service:

The class is WSExecutor.java that can be executed.

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Page 20: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

3.4. - Source Code

3.4.1. - WSExecutor.java

Main:

public static void main(String[] args) {

WSExecutor we = new WSExecutor();

we.testTopo();

}

Perform the testTopo test:

private void testTopo() {

String topo = "DONOXTI";

String lengua = "0";

boolean bprint = true;

try {

WstopobjUser[] wu = dooToponimo(topo, lengua);

if (bprint == true) {

printData(wu);

}

} catch (Exception e) {

e.printStackTrace();

}

}

Page 21: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

and the Toponimo function:

public WstopobjUser[] dooToponimo(String topo, String lengua) throws RemoteException {

//array de objetos a devolver

WstopobjUser[] wu = null;

//Creamos el proxy

BuscartoponimoProxy btp = new BuscartoponimoProxy();

//Creamos los parametros

Buscartoponimo parameters = new Buscartoponimo();

//asignamos valores

parameters.setToponimo(topo);

parameters.setLengua(lengua);

//ejecutamos el servicio

BuscartoponimoResponse bpr = btp.buscartoponimo(parameters);

//obtenemos el resultado

BuscartoponimoUser_buscartoponimo_Out bubo = bpr.getResult();

BigDecimal bd = bubo.get_return();

wu = bubo.getToponimoarrOut();

return wu;

Page 22: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

}

4. - Web client

AJAX technology allows web applications with a high degree of dynamism to be

developed. Broadly speaking, it consists of a script language (Javascript, Jscript,...)

being used on the client side to perform XML requests to a server that contains the

logics of the application.

AJAX can therefore be used to make calls to web services. The steps to be

performed are listed below to implement a website that uses JavaScript to make a

call a web service of the platform.

Specifically, the web service is going to be used to locate a item by its ID and the

building with ID D_4545 is specifically going to be searched in the street plan topic.

The search language will be Spanish.

The locate object web service is waiting an XML request with the following format:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

<soap:Body

xmlns:ns1="http://com/dfg/webservices/LocalizarPorId.wsdl/types/">

<ns1:localizaridcallejeroElement>

<ns1:identificador>D_4545</ns1:identificador>

<ns1:escala>12000</ns1:escala>

<ns1:lengua>0</ns1:lengua>

<ns1:imagen>si</ns1:imagen>

<ns1:escenario>VITO</ns1:escenario>

<ns1:anchura>640</ns1:anchura>

<ns1:altura>480</ns1:altura>

</ns1:localizaridcallejeroElement>

</soap:Body>

</soap:Envelope>

Page 23: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Therefore, the first step to be performed in Javascript would be to create the XML

document that will be sent to the web service:

var xmlDoc = createNewDocument();

The following step would be to put the heading in the XML:

var envelope = createElementNS(xmlDoc,

'http://schemas.xmlsoap.org/soap/envelope/', 'Envelope');

xmlDoc.appendChild(envelope);

var body = createElementNS(xmlDoc,

'http://schemas.xmlsoap.org/soap/envelope/', 'Body');

envelope.appendChild(body);

var parameterParent = body;

parameterParent = createElementNS(xmlDoc,

'http://com/dfg/webservices/LocalizarPorId.wsdl/types/',

'localizaridriosElement');

body.appendChild(parameterParent);

The createElementNS() and appendChild() functions create the XML structure. .

CreateElementNS() is used to create a new element in the document and

appendChild() to establish the correct hierarchical order with the document.

The following step would be allocate the values to each of the parameters that the

web service requires. In the case of the building identifier, it would be:

paramEl.appendChild(xmlDoc.createTextNode(D_4545));

parameterParent.appendChild(paramEl);

Page 24: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

The previous step needs to be performed for each of the parameters of the request

(language, image, scenario...).

In this point, the XML document has been created and would appear as follows

when displayed on the web page:

The following step is to perform the call to the web service that sends the XML that

have been created. The XmlHttpRequest object, which is implemented by the

majority of browsers, can be used to send XML from Javascript.

The XmlHttpRequest item is created in different forms depending on the Internet

browser being used. The following code would generate the desired item:

var req = null; if (window.XMLHttpRequest) { // Si no es Internet Explorer req = new XMLHttpRequest(); } else if (window.ActiveXObject) { //Si es Internet Explorer req = new ActiveXObject("Microsoft.XMLHTTP");

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Page 25: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

}

Once created, it is then configured. First, the type of request to be performed (GET

or POST) is established and the URL where the web service is located.

req.open("POST", url, false);

Then, the required “Content-Type” is then configured, in this case “text/xml”.

req.setRequestHeader("Content-Type", "text/xml");

Finally, the XML is then sent using the send() function,

req.send(xmlDoc);

All the above call be grouped in a function that receives the URL where the web

service is located and the XML to be sent and returns the service response. The

indicated code would be:

function invokeSync (url, xmlDoc) { var req = null; if (window.XMLHttpRequest) { // Si no es Internet Explorer req = new XMLHttpRequest(); } else if (window.ActiveXObject) { //Si es Internet Explorer req = new ActiveXObject("Microsoft.XMLHTTP"); } if (req) { req.open("POST", url, false); req.setRequestHeader("Content-Type", "text/xml"); req.send(xmlDoc); return req.responseXML; }

Page 26: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

}

If the web service is called with the above parameters, the following would be

returned:

<?xml version="1.0" encoding="UTF-8"?> <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns0="http://com/dfg/webservices/LocalizarPorId.wsdl/types/"> <env:Body> <ns0:localizaridcallejeroResponseElement> <ns0:result> <ns0:imagenurlOut>http://arqfotos:9876/internet/GenaImageSourcer? ?IMAGEID=164566151176& RETCONTENTTYPE=image/png&RM=FALSE </ns0:imagenurlOut> <ns0:return>OK</ns0:return> <ns0:objectOut> <ns0:listaDirecciones> <ns0:array> <ns0:nombre>SALESIANOS, CONVENTO</ns0:nombre> <ns0:seccion>002</ns0:seccion> <ns0:numero>012 </ns0:numero> <ns0:terminoMunicipal xsi:nil="1"/> <ns0:nucleoUrbano xsi:nil="1"/> <ns0:distrito>02</ns0:distrito> <ns0:municipio>AZKOITIA | 017</ns0:municipio> <ns0:codigoPostal>20720</ns0:codigoPostal> <ns0:comarca xsi:nil="1"/> <ns0:calle>AIZKIBEL KALEA | 1240</ns0:calle>

Page 27: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

</ns0:array> </ns0:listaDirecciones> <ns0:listaActividades xsi:nil="1"/> </ns0:objectOut> </ns0:result> </ns0:localizaridcallejeroResponseElement> </env:Body> </env:Envelope>

The XML returned by the web service could be analysed in Javascript in order to

obtain information and show it appropriately on a web page or it can simply display

the returned XML:

Page 28: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

Finally, the complete code is displayed of the functions used in this document to

perform the petition and a new main function that performs the whole process. The

function is LocalizarPorIdSoapHttpPort_localizaridcallejero() and receives the

necessary data as parameters to perform the web service request, generates the

necessary XML, sends it to the service and finally, it returns the XML response of

the server.

function LocalizarPorIdSoapHttpPort_localizaridcallejero(_identificador, _escala, _lengua, _imagen, _escenario, _anchura, _altura) { var xmlDoc = createNewDocument(); var envelope = createElementNS(xmlDoc, 'http://schemas.xmlsoap.org/soap/envelope/', 'Envelope'); xmlDoc.appendChild(envelope); var body = createElementNS(xmlDoc,

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Page 29: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

'http://schemas.xmlsoap.org/soap/envelope/', 'Body'); envelope.appendChild(body); var parameterParent = body; parameterParent = createElementNS(xmlDoc, 'http://com/dfg/webservices/LocalizarPorId.wsdl/types/', 'localizaridcallejeroElement'); body.appendChild(parameterParent); var paramEl = createElementNS(xmlDoc, 'http://com/dfg/webservices/LocalizarPorId.wsdl/types/', 'identificador'); paramEl.appendChild(xmlDoc.createTextNode(_identificador)); parameterParent.appendChild(paramEl); var paramEl = createElementNS(xmlDoc, 'http://com/dfg/webservices/LocalizarPorId.wsdl/types/', 'escala'); paramEl.appendChild(xmlDoc.createTextNode(_escala)); parameterParent.appendChild(paramEl); var paramEl = createElementNS(xmlDoc, 'http://com/dfg/webservices/LocalizarPorId.wsdl/types/', 'lengua'); paramEl.appendChild(xmlDoc.createTextNode(_lengua)); parameterParent.appendChild(paramEl); var paramEl = createElementNS(xmlDoc, 'http://com/dfg/webservices/LocalizarPorId.wsdl/types/', 'imagen'); paramEl.appendChild(xmlDoc.createTextNode(_imagen)); parameterParent.appendChild(paramEl); var paramEl = createElementNS(xmlDoc, 'http://com/dfg/webservices/LocalizarPorId.wsdl/types/', 'escenario'); paramEl.appendChild(xmlDoc.createTextNode(_escenario)); parameterParent.appendChild(paramEl); var paramEl = createElementNS(xmlDoc, 'http://com/dfg/webservices/LocalizarPorId.wsdl/types/', 'anchura'); paramEl.appendChild(xmlDoc.createTextNode(_anchura)); parameterParent.appendChild(paramEl); var paramEl = createElementNS(xmlDoc, 'http://com/dfg/webservices/LocalizarPorId.wsdl/types/', 'altura'); paramEl.appendChild(xmlDoc.createTextNode(_altura)); parameterParent.appendChild(paramEl); var responseDoc = invokeSync('http://arqfotos:8888/dfg-loid/LocalizarPorIdSoapHttpPort', xmlDoc); return responseDoc; } function createElementNS (xmlDoc, namespace, localName) { var element = null; if (typeof xmlDoc.createElementNS != 'undefined') { element = xmlDoc.createElementNS(namespace, localName); } else if (typeof xmlDoc.createNode != 'undefined') { if (namespace) { element = xmlDoc.createNode(1, localName, namespace); } else { element = xmlDoc.createElement(localName); } }

Page 30: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

return element; }

function createNewDocument () { var xmlDoc = null; if (document.implementation && document.implementation.createDocument) { xmlDoc = document.implementation.createDocument("", "", null); } else if (window.ActiveXObject){ xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); } return xmlDoc; } function invokeSync (url, xmlDoc) { var req = null; if (window.XMLHttpRequest) { req = new XMLHttpRequest(); } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); } if (req) { req.open("POST", url, false); req.setRequestHeader("Content-Type", "text/xml"); req.send(xmlDoc); return req.responseXML; } }

5. - PHP client application package 5.1. – Introduction In this case, the implementation in PHP is described of a client that uses a web

service also using the WSDL description archive

Page 31: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

5.2. – Requirements

PHP Version 5.1.2.

NUSOAP version 0.7.2. library (http://sourceforge.net/projects/nusoap)

5.3. - Source Code

Código Fuente

<?php // Load the libraries. require_once('./lib/nusoap.php'); // Production $wsdl="http://b5m.gipuzkoa.net/ws/dfg-dibujar-context-root/DibujarSoapHttpPort?WSDL"; // Read the WSDL and create the proxies $client=new soapclient($wsdl, 'wsdl'); // Change the URL endpoint to $wsdl less the last 5 characters $client->operations['dibujarimagen']['endpoint'] = substr($wsdl,0,strlen($wsdl)-5); // Force the char sets $client->soap_defencoding = 'UTF-8'; $client->decode_utf8 = false; // Layer control example $mapasel=array('nombre'=>'L%EDmites municipales','estado'=>'n','tipo'=>'Mapa'); // Parameter Example $params=array(array('ix1'=>'540000','iy1'=>'4740000','ix2'=>'610000','iy2'=>'4810000','iwidth'=>'500','iheight'=>'300','iescenario'=>'PUBLI','lengua'=>'0','mapaselectarr'=>$mapasel)); // Error check. $err = $client->getError(); if ($err) { echo 'Constructor error' . $err ;

Page 32: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

} // Call Web Service. $result = $client->call('dibujarimagen', $params);

// Error check. if ($client->fault) { echo 'Fault'; print_r($result); } else { $err = $client->getError(); if ($err) { echo 'Error' . $err ; } } // See the results print_r($result); // Debugging tools //echo $client->response; //echo $client->request; //echo $client->debug_str; ?>

Page 33: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

if the PHP example is executed from a UNIX shell, the following result will be seen. . $ php dib.php Array ( [result] => Array ( [return] => 1 [oimagepathOut]=> http://b5m.gipuzkoa.net/internet/GenaImageSourcer?IMAGEID=2034743655&RETCONTENTTYPE=image/png ) ) To recover the image, a http request with the URL given in the oimagepathOut

variable is executed.

Page 34: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Example 2: Call the Web Service to see the available layers.

<?php // Load the libraries. require_once('./lib/nusoap.php'); // Production $wsdl="http://b5m.gipuzkoa.net/ws/dfg-dibujar-context-root/DibujarSoapHttpPort?WSDL"; // Read the WSDL and create the proxies $client=new soapclient($wsdl, 'wsdl'); // Cambiar el endpoint URL a $wsdl menos los ultimos 5 chars $client->operations['mapasdisponibles']['endpoint'] = substr($wsdl,0,strlen($wsdl)-5); // Force the char sets. $client->soap_defencoding = 'UTF-8'; $client->decode_utf8 = false; // Parameter Example $params1=array(array('categoria'=>'PUBLI','lengua'=>'0')); // Error check. $err = $client->getError(); if ($err) { echo 'Constructor error' . $err ; } // Call Web Service. $result = $client->call('mapasdisponibles', $params1); if ($client->fault) { echo 'Fault'; print_r($result); } else { $err = $client->getError(); if ($err) { echo 'Error' . $err ; } else { // Ver los resultados print_r( $result ) ; } } ?>

Page 35: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

If the PHP example is executed from a UNIX shell, the following result will be seen. $ php mapas.php Array ( [result] => Array ( [return] => Array ( [wsmessage] => OK [wsstatus] => 5 ) [objectOut] => Array ( [0] => Array ( [MActivado] => s [GActivado] => S [clase] => AltimetrÃa [grupo] => Nada [descripcion] => AltimetrÃa 100 [mapa] => alti_100 [CActivado] => S ) [1] => Array ( [MActivado] => s [GActivado] => S [clase] => AltimetrÃa [grupo] => Nada [descripcion] => AltimetrÃa 25 [mapa] => alti_25 [CActivado] => S ) . . . ) ) )

Page 36: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

$ php mapas.php Array ( [result] => Array ( [return] => Array ( [wsmessage] => OK [wsstatus] => 5 ) [objectOut] => Array ( [0] => Array ( [MActivado] => s [GActivado] => S [clase] => AltimetrÃa [grupo] => Nada [descripcion] => AltimetrÃa 100 [mapa] => alti_100 [CActivado] => S ) [1] => Array ( [MActivado] => s [GActivado] => S [clase] => AltimetrÃa [grupo] => Nada [descripcion] => AltimetrÃa 25 [mapa] => alti_25 [CActivado] => S ) . . . ) ) )

Page 37: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

6. - PDA Windows Mobile Application Package 6.1. – Introduction The development of PDA client has been performed with the Microsoft .Net Compact

Framework 2.0 with the Visual Studio 2005 development environment and the C#

programming language. The described prototype accesses to the DibujarImagen

Web Service.

6.2. - Creating the PDA project

In order to create a project for a PDA, a “Device Application” type project is

created.

When you select “OK”, a form appears in a PDA image.

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Page 38: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

6.3 Creating a consumer application package for the

DibujarImagen' web service

Select “Add New Data Source” option from the Data menu

The first window of the Wizard will appear.

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Page 39: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

Select the “Web Service” option and the “Next” button and the following web

reference window will appear.

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

In the URL text box, enter the URl of the WSDL file for the web service that tallies

with the web service to be used.

Example: Dibujar.

http://b5m.gipuzkoa.net/dfg-dibujar-context-root/DibujarSoapHttpPort?WSDL

After a few seconds, a list of the methods that the service has available will appear.

Page 40: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

Select the “Add Reference” and the following window appears.

When you select "Finish", the Wizard window closes and the new reference is added

to the solution and the "Data Source" creates.

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Page 41: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

6.3.1. - Add controls to the application package

A Button type control is added to launch the web service and a PictureBox type

control is added to view the result.

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Page 42: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

6.3.2. - C# Code The access code to the Web Service is added to the “button1_Click” method.

Double clicking on the design mode button creates the empty class in codification

mode.

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace DeviceApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { } } }

Page 43: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Add the following the code lines to the button1_Click() method. private void button1_Click(object sender, EventArgs e)

{

// Array de capa adicionales a nulo.

net.gipuzkoa.b5m.WsmapasselectUser[] userArray1 = null;

Cursor.Current = Cursors.WaitCursor;

// Crear una nueva instancia de la clase del Web Service.

net.gipuzkoa.b5m.Dibujar webDibImg =

new net.gipuzkoa.b5m.Dibujar();

// Llama al Web Service y recoger la respuesta.

net.gipuzkoa.b5m.DibujarUser_dibujarimagen_Out out1 =

webDibImg.dibujarimagen("520000","4740000","610000",

"4810000", pictureBox1.Width.ToString(),

pictureBox1.Height.ToString(),

"PUBLI", "0", userArray1);}

// Pedir y dibujar el mapa Uri uri1 = new Uri(out1.oimagepathOut);

HttpWebRequest request1 =

(HttpWebRequest)WebRequest.Create(uri1);

HttpWebResponse response1 =

(HttpWebResponse)request1.GetResponse();

StreamReader reader1 = new

StreamReader(response1.GetResponseStream());

Bitmap bitmap1 = new Bitmap(reader1.BaseStream);

pictureBox1.Image = bitmap1;

reader1.Close();

Cursor.Current = Cursors.Default;

}

Page 44: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

6.3.3 - Test the example with the emulator. When the application is executed, the following deploy window will appear.

Select the “Pocket PC 2003 SE Emulator” option and the “Deploy” button. The

software will be installed in the emulator and a window will appear with the

application running.

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Page 45: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

In order to establish the Internet connection, the physical connection is emulated

with ActiveSync, which is carried out using the "Device Emulator Manager" which is

run from the "Tools" menu.

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion

Once the “Emulator Manager” is running, select the “Pocket PC 2003 SE Emulator”

option and then using the right button, select the "Cradle” option.

Page 46: DFG Web Services Implementation of Web Service Client ...b5m.gipuzkoa.eus/web5000/docu/en/en_clientes_webservices.pdfDFG Web Services - Implementation of Web Service Client Applications

DFG Web Services - Implementation of Web Service Client Applications

The ActiveSync icon will change from grey to green and the association window will

appear where the "Guest" option can be selected. Once connected, select the

button to launch the request to the Web Service and after a few seconds, an image

of Gipuzkoa will appear.

| Gipuzkoa.net |Department for the Arrangement and Territorial Promotion