alejandro mezcua mvp device application development [email protected]
TRANSCRIPT
![Page 1: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/1.jpg)
![Page 2: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/2.jpg)
Alejandro MezcuaMVP Device Application Developmenthttp://www.byteabyte.net/[email protected]
![Page 3: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/3.jpg)
Direccionamiento de un dispositivoCambia entre muchas redesCambia de direcciones
Conectado ocasionalmenteSe puede apagarZonas de no cobertura
¿Cómo enviar y recibir mensajes en esta situación?
![Page 4: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/4.jpg)
Para el direccionamiento de un dispositivo
Usar una dirección independiente de la conexión (email)
Para las conexiones ocasionalesAlmacenar los mensajes en un sitio accesible
![Page 5: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/5.jpg)
Estos requisitos los cumple Microsoft Exchange 2007
Direcciones de email por usuarioBuzones para el almacenamiento temporal de los mensajesConectividad por diversos medios
![Page 6: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/6.jpg)
Comunicación asíncrona por naturaleza
No se puede saber¿Cuándo llega un mensaje?¿Se ha recibido?
Diseñar las aplicaciones con esto en mente
![Page 7: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/7.jpg)
Transportes WCF (Windows Communication Foundation) que aprovechan Microsoft Exchange Server 2007
Versión para PCVersión para Windows MobileDesarrollados en conjunto por el equipo de Exchange y el de .NET Compact Framework
![Page 8: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/8.jpg)
Existe transporte para servicios Web WCF
Se pueden crear nuevos transportes en la infraestructura de WCF
![Page 9: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/9.jpg)
Windows MobileWindowsMobileMailBinding
PCsExchangeWebServiceMailBinding
Incluido con .NET Compact Framework 3.5 SDK
![Page 10: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/10.jpg)
Usa la conexión de ActiveSyncSi ActiveSync está conectado al PC, conecta directamenteSi se ha configurado AUTD (Always Up To Date) se realiza la sincronización al llegar nuevos elementos
![Page 11: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/11.jpg)
Usa Exchange Web ServicesCada cierto tiempo (configurable) conecta con el servidor para ver si hay nuevos mensajes (POLL)
![Page 12: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/12.jpg)
La comunicación ha de ir codificadaConexiones https
ActiveSync usa https
Los equipos han de confiar en el emisor del certificado
Si no se verifica el código genera excepciones
![Page 13: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/13.jpg)
Un mensaje se envía a una dirección de email y a un canal (identificador texto)
Esto permite disponer de varias aplicaciones usadas desde la misma dirección de email (con diferentes canales)
Equivalente a direcciónIP:Puerto
![Page 14: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/14.jpg)
Un mensaje es una objeto serializado a Xml
Se definen las clases como serializablesEs necesario definir un serializador para establecer cómo se crea el Xml a partir de la clase
Clase que herede de XmlObjectSerializer
Suele bastar con serialización simpleSe pueden compartir entre proyectos PC y .NET CF
Los dos han de entender los mismos mensajes
![Page 15: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/15.jpg)
WindowsMobileMailBinding o ExchangeWebServiceMailBinding dependiendo del caso
Se usará tanto para enviar como para recibir mensajes.
_binding = new WindowsMobileMailBinding();_binding.AcceptExistingMessages = true;…_binding = new ExchangeWebServiceMailBinding( new Uri(_exchangeServerUrl), new System.Net.NetworkCredential(_exchangeServerMailbox,
_exchangeServerPassword) );
![Page 16: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/16.jpg)
Necesario para enviar mensajesMismo código en PC y Compact Framework
BindingParameterCollection parameters = new BindingParameterCollection();_channelFactory = _binding.BuildChannelFactory<IOutputChannel>(parameters);_channelFactory.Open();
_outChannel = _channelFactory.CreateChannel( new System.ServiceModel.EndpointAddress(
MailUriHelper.CreateUri(_channelName, _email))
);_outChannel.Open();
![Page 17: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/17.jpg)
SimpleObjectSerializer serializer = new SimpleObjectSerializer(typeof(ObjetoAEnviar));
System.ServiceModel.Channels.Message msg = System.ServiceModel.Channels.Message.CreateMessage(
MessageVersion.Soap12WSAddressing10, _accion, _objetoAEnviar, serializer);
_outChannel.Send(msg);
Serializarlo antes al formato requeridoMismo código en PC y Compact Framework
El canal se puede quedar abierto para reutilizarlo
![Page 18: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/18.jpg)
Necesario para leer mensajesBucle en thread secundarioMismo código en PC y Compact FrameworkSe puede usar la cabecera “action” para determinar el tipo de mensaje
El servidor y el cliente han de estar de acuerdo en la cabecera, es texto.
![Page 19: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/19.jpg)
BindingParameterCollection parameters = new BindingParameterCollection();IChannelListener<IInputChannel> listener = _binding.BuildChannelListener<IInputChannel>( MailUriHelper.CreateUri(_channelName, _emailAddress), parameters);listener.Open();IInputChannel inputChannel = listener.AcceptChannel();inputChannel.Open();listener.Close(); // Se puede cerrar una vez aceptado el canal.System.ServiceModel.Channels.Message reply = null;while (_processMessages){
if(inputChannel.TryReceive(new TimeSpan(0, 0, 0, 0, 2000), out reply)) { if(reply != null) { // Se ha recibido un mensaje, ver su tipo if(reply.Headers.Action == “accion”) {
// Realizar tarea con el mensaje }
} } } inputChannel.Close(); listener.Close();
![Page 20: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/20.jpg)
![Page 21: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/21.jpg)
Mostrar el uso del transporte de email de WCF en .NET Compact Framework 3.5
Ver un ejemplo de integración de una solución completa (móvil – Web)
![Page 22: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/22.jpg)
![Page 23: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/23.jpg)
![Page 24: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/24.jpg)
Aplicación ASP.NETSe encarga de
Mostrar las localizaciones en un mapa de Virtual Earth
![Page 25: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/25.jpg)
![Page 26: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/26.jpg)
Aplicación Windows Forms .NET Compact Framework 3.5Se encarga de
Comunicarse con el GPSLocalización desde la aplicación Windows MobileLocalización solicitada por la central
Mensaje WCF desde la aplicación PC
Enviar mensajes a la central mediante ActiveSync
![Page 27: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/27.jpg)
![Page 28: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/28.jpg)
Aplicación Windows FormsSe encarga de
Solicitar localizaciones puntuales de usuarios
Manda mensaje WCF a Windows Mobile
Mostrar las localizaciones obtenidas en un mapa
Recibe mensajes WCF con datos de la posiciónIntegra interface Web para mostrar la localización en Virtual Earth
![Page 29: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/29.jpg)
![Page 30: Alejandro Mezcua MVP Device Application Development alejandro.mezcua@byteabyte.net](https://reader035.vdocuments.pub/reader035/viewer/2022070304/54d01c334979592e558b464f/html5/thumbnails/30.jpg)
Alejandro MezcuaMVP Device Application Developmenthttp://www.byteabyte.net/[email protected]