accessing WCF services in Wince

Source: Internet
Author: User

As this article is not wince development and popularization of the article, so some wince development and the foundation of the development of WCF also ask Baidu and Google to find answers, and then combined with this article developed wince how to access WCF, thank you.

Development environment

Ide:visual Studio 2008 (2010, 2012, 2013 currently not supported)

Os:win 7 (64-bit)

Tools:activesync Win7 v6.1 (Device Center, Network for Pocket PC 2003 simulator)

Simulator Network Connection Introduction: http://www.jb51.net/softjc/42088.html

Create a WinCE Project

Please forgive this article is not wince development popularization, so please Baidu bar.

WCF Service-side

Key code in app. Config

<service behaviorconfiguration="Systemdispatchserviceforpdabehavior"Name="SYSTEMMANAGESERVICELIBRARY.SYSTEMDISPATCHSERVICEFORPDA"> <!--PDA system assignment--<endpoint address="Http://localhost:20003/SystemDispatchForPDA/SystemDispatchServiceForPDA"binding="webhttpbinding"Contract="SystemManageServiceLibrary.SystemDispatch.ISystemDispatchServiceForPDA"> </endpoint> <!--PDA System allocation metadata--<endpoint address="Http://localhost:20003/SystemDispatchForPDA/SystemDispatchServiceForPDA/mex"binding="mexhttpbinding"contract="IMetadataExchange"/> "Http://localhost:20003/SystemDispatchForPDA"/> </baseAddresses> <timeouts opentimeout="00:00:30"/>  
  View Code 
  

Service contract-Advertise WCF rest (detailed can Baidu search for WCF rest)

[ServiceContract] Public InterfaceISYSTEMDISPATCHSERVICEFORPDA {/// <summary>        ///PDA gets cluster information/// </summary>        /// <param name= "Strpda_imei" >PDA Internal Factory serial number</param>        /// <returns></returns>[OperationContract]//uritemplate is actually the URL rule to send the request via the HTTP protocol, replace {Strpda_imei} with the real PDA serial number[WebGet (UriTemplate ="Getclusterinfo/{strpda_imei}")] CLUSTER getclusterinfo (stringStrpda_imei); }
View Code

WinCE

Httpwrapper.cs-http requested encapsulation, access to WCF-provided rest services

     Public classHttpwrapper { Public Static stringSendRequest (stringURL) {HttpWebResponse response=NULL; HttpWebRequest Request= WebRequest.Create (URL) asHttpWebRequest; Request. Method="GET"; Request. AllowWriteStreamBuffering=false; Request. KeepAlive=true; Request. ContentType="application/x-www-form-urlencoded"; //receive the returned pageResponse = Request. GetResponse () asHttpWebResponse; Stream Responsestream=Response.            GetResponseStream (); StreamReader Reader=NewSystem.IO.StreamReader (Responsestream, Encoding.UTF8); stringStrresult =Reader.            ReadToEnd (); Reader.            Close (); Response.            Close (); returnstrresult; }    }
View Code

Xmladapter.cs-xml adapter for converting XML into classes

     Public classXMLAdapter { Public StaticT converttoclass<t> (stringStrxml)whereT:class{XmlSerializer XmlSerializer=NewXmlSerializer (typeof(T)); MemoryStream Reader=NewMemoryStream (Encoding.UTF8.GetBytes (strxml)); T obj= Xmlserializer.deserialize (reader) asT; Reader.            Dispose (); returnobj; }    }
View Code

Calling methods

        Private Static stringURL ="http://ip:20003/SystemDispatchForPDA/SystemDispatchServiceForPDA/";  Public StaticCLUSTER Getclusterinfo (stringStrpda_imei) {            stringStrresponse = httpwrapper.sendrequest (URL +"getclusterinfo/"+Strpda_imei); CLUSTER CLUSTER= xmladapter.converttoclass<cluster>(strresponse); returncluster; }

Really need to pay attention to is actually a few points:

1. Installing the Equipment Center

2. Setting up the emulator network connection

3.WCF REST

4.WinCE parsing of the XML returned by WCF, and how to splice access to the URL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.