Сетевое взаимодействие 11/15/2018 8:27 PM Сетевое взаимодействие Михаил Черномордиков Developer Evangelist, Microsoft Россия mikcher@microsoft.com http://blogs.msdn.com/mikcher http://www.remix.ru © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Содержание Взаимодействие JavaScript Класс WebClient Классы HttpWebRequest/HttpWebResponse Подписка на WCF Web Services Подписка SOAP Web Services Сокеты http://www.remix.ru
Класс WebClient Похож на Downloader Обеспечивает асинхронный кросс-доменный доступ к сетевым ресурсам Простой в использовании: System.Net.WebClient client = new System.Net.WebClient(); client.DownloadStringCompleted+=new DownloadStringCompletedEventHandler(client_DownloadStringCompleted); client.DownloadStringAsync(myURI); http://www.remix.ru
demo Web Client http://www.remix.ru 11/15/2018 8:27 PM © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
HttpWebRequest / HttpWebResponse Обеспечивает асинхронный кросс-доменный доступ к сетевым ресурсам Позволяет получить контроль над сообщением HTTP Очень полезный при обращении к существующим основанным на формах (т.e. HTTP-POST) ресурсах, которые активно используются в таких технологиях как PHP http://www.remix.ru
Разработка для HTTP Post Uri uri = new Uri("http://localhost:8002/Sample2Web/GetData.ashx"); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.BeginGetRequestStream(new AsyncCallback(RequestProceed), request); void RequestProceed(IAsyncResult asyncResult) { … } void ResponseProceed(IAsyncResult asyncResult) { … }
HttpWebRequest and HttpWebResponse 11/15/2018 8:27 PM HttpWebRequest and HttpWebResponse demo http://www.remix.ru © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Подписка на WCF Web Services Определение сервисов с помощью стандартных контрактов WCF (т.e. [DataMember] и так далее) Использование Visual Studio для создание прокси сервисов (based on HttpWebReq/Resp) Silverlight использует этот прокси асинхронно
demo WCF и Silverlight http://www.remix.ru 11/15/2018 8:27 PM © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Подписка на SOAP Web Services Веб-сервисы должны предоставлять файл WSDL и сервер должен иметь crossdomain.xml или clientaccesspolicy.xml, правильно настроенный и расположенный Использование Visual Studio для создания прокси сервиса (основано на HttpWebReq/Resp) Silverlight использует этот прокси асинхронно
Поддержка сокетов В Silverlight возможно сетевое взаимодействие на базе сокетов Ограничения Поддерживаются только порты из диапазона 4502-4534 Коммуникация возможна только с тем же доменом, на котором находится элемент управления Необходим полиси-сервер, расположенный на порту 943 До инициализации соединения Silverlight опрашивает порт 943 для получения информации о полиси, которая содержит разрешенные порты и протоколы
demo Sockets http://www.remix.ru 11/15/2018 8:27 PM © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Сетевое взаимодействие 11/15/2018 8:27 PM Сетевое взаимодействие Михаил Черномордиков Developer Evangelist, Microsoft Россия mikcher@microsoft.com http://blogs.msdn.com/mikcher http://www.remix.ru © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.