Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C# 2008 Step by Step.pdf
Скачиваний:
26
Добавлен:
25.03.2016
Размер:
13.96 Mб
Скачать

644

Part VI Building Web Applications

Chapter 30 Quick Reference

To

 

Do this

Create a Web service

Use the WCF Service template. Define a service contract that specifies the

 

 

Web methods exposed by the Web service by creating an interface with

 

 

the ServiceContract attribute. Tag each method with the OperationContract

attribute. Create a class that implements this interface.

Display the description of a Web service

Right-click the .svc file in Solution Explorer, and click View in Browser. Internet Explorer runs, moves to the Web service URL, and displays a page describing how to create a client application that can access the Web service. Click the WSDL link to display the WSDL description of the Web service.

Pass complex data as Web method parameters and return values

Define a class to hold the data and tag it with the DataContract attribute. Ensure that each item of data is accessible either as a public field or through a public property that provides get and set access. Ensure that the class has a default constructor (which might be empty).

Add a service reference to a

On the Project menu, click Add Service Reference. Type the URL of the Web

client application and create

service in the Address text box at the top of the dialog box, and then click Go.

a proxy class

Specify the namespace for the proxy class, and then click OK.

 

 

Invoke a Web method

Create an instance of the proxy class. Call the Web method using the

 

proxy class.

 

 

John Sharp

John Sharp is a Principal Technologist at Content Master (www.contentmaster.com), part of CM Group, a technical authoring company in the United Kingdom. He researches and develops technical content for training courses, seminars, and white papers. John is deeply involved with Microsoft .NET Framework application development and interoperability. He

has written papers and courses, built tutorials, and delivered conference presentations covering distributed systems and Web services, application migration and interoperability between

Microsoft Windows/.NET Framework and UNIX/Linux/Java, as well as development using the C# and J# languages. John has also authored Microsoft Windows Communication Foundation Step by Step and Microsoft Visual J# Core Reference, both published by Microsoft Press.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]