} [DataMember] public double Longitude { get { return _longitude; } set { _longitude = value; } } } By marking the classes with the [DataContract] and [DataMember] attributes, an XSD file is created describing the complex types. Clients use this file to determine what to supply the service and what to expect as a return type. Figure 13-7 shows the portion of the XSD file created for the Location type returned by the service. ocs:element min0ccurs="0" name-'Latitude" type="xs:double" {> ocs:element minGccurs="0" name="Longitude" type="xs:double" /> nillable-'true" type-'tns:Location" /> ■ocsielement name-'Location" Figure 13-7. XSD file defining the Location type, as displayed in a browser Let's put what you've learned so far to work by building a simple service that supplies a list of stores from the Pubs database. The service will then be consumed in a Silverlight client to display a list of stores. ACTIVITY 13-1. CREATING AND CONSUMING A WCF SERVICE In this activity, you will become familiar with the following: • Creating a WCF Service. Consuming a WCF Service in a Silverlight client. Creating a WCF Service To create the WCF Service, follow these steps: 1. Start Visual Studio. Select File > New > Project. Choose a Silverlight Application under the C# Projects folder. Rename the project to Act13_1 and click the OK button. The next screen asks if you want to host the Silverlight application in a new web site. It also asks you what version of Silverlight you want to use. Accept the defaults and click OK. Right-click on the Act13_1 .Web project node in the Solution Explorer window and select Add > New Item. In the Add New Item window, click on the Web node in the Installed Templates section. Select the WCF Service template, rename it to PubsService, and click the Add button (see Figure 13-8).
} [DataMember] public double Longitude { get { return _longitude; } set { _longitude = value; } } } By marking the classes with the [DataContract] and [DataMember] attributes, an XSD file is created describing the complex types. Clients use this file to determine what to supply the service and what to expect as a return type. Figure 13-7 shows the portion of the XSD file created for the Location type returned by the service. ocs:element min0ccurs="0" name-'Latitude" type="xs:double" {> ocs:element minGccurs="0" name="Longitude" type="xs:double" /> ■ocsielement name-'Location" nillable-'true" type-'tns:Location" /> Figure 13-7. XSD file defining the Location type, as displayed in a browser Let's put what you've learned so far to work by building a simple service that supplies a list of stores from the Pubs database. The service will then be consumed in a Silverlight client to display a list of stores. ACTIVITY 13-1. CREATING AND CONSUMING A WCF SERVICE In this activity, you will become familiar with the following: • Creating a WCF Service. Consuming a WCF Service in a Silverlight client. Creating a WCF Service To create the WCF Service, follow these steps: 1. Start Visual Studio. Select File > New > Project. Choose a Silverlight Application under the C# Projects folder. Rename the project to Act13_1 and click the OK button. The next screen asks if you want to host the Silverlight application in a new web site. It also asks you what version of Silverlight you want to use. Accept the defaults and click OK. Right-click on the Act13_1 .Web project node in the Solution Explorer window and select Add > New Item. In the Add New Item window, click on the Web node in the Installed Templates section. Select the WCF Service template, rename it to PubsService, and click the Add button (see Figure 13-8).
68793928390368.docx