Top Banner
18

Alejandro Mezcua MVP Device Application Development [email protected]

Jan 03, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net
Page 2: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net

Alejandro MezcuaMVP Device Application [email protected]://www.byteabyte.net/

Page 3: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net

Mostrar el uso de servicios Web WCF en .NET Compact Framework 3.5

Ver un ejemplo de integración de una solución completa (móvil – Web)

Page 4: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net

Internet

GPS

Visualización en un PCEnvío

de foto y

notas + gps (

si disp

onible)

con W

CF

Servidor Web

PC

Tomar foto con el móvil

Internet

GPS

Visualización en un PCEnvío

de foto y

notas + gps (

si disp

onible)

con W

CF

Servidor Web

PC

Tomar foto con el móvil

Page 5: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net
Page 6: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net

Servicio creado en una aplicación Web ASP.NETBinding básico

Único utilizable desde .NET CF

<endpoint address="" binding="basicHttpBinding" bindingConfiguration="fotoUploaderConfig” contract="LugaresVisitadosWebSite.IFotoUploader">

Page 7: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net

Ampliado el límite de elementos aceptables para un parámetro de tipo array

Por omisión 32kUna imagen es un byte[]

<bindings><basicHttpBinding>

<binding name="fotoUploaderConfig"> readerQuotas maxArrayLength="131072" /></binding>

</basicHttpBinding></bindings>

Page 8: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net

Servicio alojado en IISGuarda fotos y metadatos (posición) en App_DataNo accesible con Server.MapPath

El contexto habitual de IIS no está accesible en WCF por omisión

string fotoLocalPath = String.Format("{0}\\{1}\\{2}", HostingEnvironment.ApplicationPhysicalPath,

"App_Data", fotoFileName);

Page 9: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net
Page 10: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net

Aplicación Windows Forms .NET CF 3.5Creación del proxy usando NetCFSvcUtil.exe

Instalado con los “Power Toys for .NET CF 3.5” (no viene con Visual Studio de serie)

C:\Program Files\Microsoft.NET\SDK\CompactFramework\v3.5\bin>Netcfsvcutil.exe /language:cs http://[servicio].svc

Page 11: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net

Incluir los archivos generados en el proyecto

CFClientBase.cs, FotoUploader.cs

Usar el proxy para invocar al servicio web

FotoUploaderClient uploader = new FotoUploaderClient(FotoUploaderClient.CreateDefaultBinding(),

new System.ServiceModel.EndpointAddress([UrlServicio]));

if (!uploader.UploadFoto(fileByteBuffer, latitud, longitud, notas))…

Page 12: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net
Page 13: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net

Permite mostrar las fotos en tamaño completo o reducido

Al estar en App_Data no son accesibles directamente, se usa un HttpHandler

http://[server]/[dir]/fotoHandler.ashx?fileName=[fileInApp_Data]&width=[imageWidth]

Page 14: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net

Las fotos en el mapa se muestran desde JavaScript

Se usa un servicio WCF que expone los datos en formato de JSON (fotosCoordenadas.svc)<endpointBehaviors>

<behavior name="jsonBehavior" ><enableWebScript/>

</behavior></endpointBehaviors>…<endpoint address=““ binding="webHttpBinding“

contract="LugaresVisitadosWebSite.IFotosCoordenadas"behaviorConfiguration="jsonBehavior">

Page 15: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net

Desde ASP.NET AJAX se accede al servicio mediante una referencia

Desde JavaScript se usa como un objeto JavaScript

<asp:ScriptManager ID="ScriptManager" runat="server"><Services>

<asp:ServiceReference Path="~/fotosCoordenadas.svc" /></Services>

</asp:ScriptManager>

function mapReady(){

var ws = new byteabyte.net.samples.IFotosCoordenadas();ws.GetFotos(getGetFotosComplete);

}

Page 16: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net

El nombre a usar en JavaScript lo debe dar intellisense, si no, acceder al servicio y ver qué devuelve

La llamada es asíncrona, en la respuesta se tienen objetos (según se exporten en el servicio)

http://localhost/lugaresvisitados/fotoscoordenadas.svc/js

function getGetFotosComplete(result){

…for(var i = 0; i < result.length; i++){

var ve = new VELatLong(result[i].Latitud, result[i].Longitud); …

}

Page 17: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net
Page 18: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net

Alejandro MezcuaMVP Device Application Developmenthttp://www.byteabyte.net/[email protected]