Using compact WCF-BasicHTTPBinding

Using compact WCF-BasicHTTPBinding

The first of the two bindings provided out of the box with Compact WCF is the BasicHTTPBinding. This is easy to understand because it is essentially identical to making a call to a Web service. Your application sends an HTTP request to the WCF service using a SOAP-encoded message and waits for the HTTP response. In contrast with the store-and-forward e-mail transport, no unsolicited messaging is possible, so the WCF service can send messages only in a response to a request from the client. The connectivity options are essentially the same as those for a Web service

 

Creating a WCF Service for Compact WCF Clients The standard way to create a WCF service is to define a class annotated with the [DataContract] attribute that describes the serializable class that you use to encapsulate the data for transfer, and an interface annotated with the [ServiceContract] attribute that describes the operations exposed by the service. Then, to write the implementation of the service, you create a class that implements the service contract interface, such as the following example:

 

Creating a WCF Service for Compact WCF Clients

 

An example of a class called MobileWCFObject that we use as our message payload and a custom serializer class that we use to serialize and deserialize it. You need to add a reference to System.ServiceModel and System.Xml.Serialization to your project.

 use the classes on both the client and the server. 

在这里可以设定message的type,可以用string[], byte[], int[], 就差不多你想传什么就传什么了

transmit data whatever you want;

其实coding of message’s define 都在这里

Definition of a Class for Transfer over WCF with Its Serializer

 

One thing that distinguishes WCF from Web Services is that-with the appropriate coding-you can host WCF services in any process, not just in IIS. For example, you can create a Windows Service or a simple Windows Forms application, add a reference to the project containing the common code from above code, and write code to programmatically build a channel, listen on a specific port, and respond to requests.

WCF Service for Compact WCF Clients

 

 

 Programming the WCF Client On the device side, the first thing to realize is that in Compact WCF, unlike in WCF for the full .NET Framework, there is no support for configuration files to define to which address to make the request or the binding to use. Coupled with the requirement for custom serialization already discussed, the result requires rather more code than you may be accustomed to when programming WCF clients in the full .NET Framework.

 

Compact WCF Client

 

 以上就是compact WCF-BasicHTTPBinding 的基本应用。

 

 

 

 

posted @ 2009-03-26 06:24  frankAvanel  阅读(652)  评论(0编辑  收藏  举报