Previous learn WCF (2)--the development of WCF services introduced the development Service program, this development of a client program, there are mainly three scenarios:
Add a Web Reference
Using the SvcUtil.exe tool
Programming Scenarios
1. Add a Web Reference
This is basically consistent with the method of adding a reference Web service, and enter URL:HTTP://LOCALHOST:39113/WCFSERVICETEXT/WCFSTUDENTTEXT.SVC in the dialog box that adds the reference
To name WCF, click the Add Reference button to complete the following tasks:
(1) Download the WSDL file for Student Management service from the specified URL
(2) Generate proxy class Wcfstudenttext, it is the proxy of server Wcfstudenttext, realize the server contract Istuservicecontract.
(3) Configuration settings for generating responses
Now we can communicate with the Student Information Management Service with the proxy class Wcfstudenttext. Add a page to the site, put a GridView and ObjectDataSource
<div>
<asp:gridview id= "GridView1" runat= "server" backcolor= "white"
Borderc Olor= "#DEDFDE" borderstyle= "None" borderwidth= "1px" cellpadding= "4"
datasourceid= "ObjectDataSource1" Fore Color= "Black" gridlines= "Vertical"
<rowstyle backcolor= "#F7F7DE"/>
<footerst YLE backcolor= "#CCCC99"/>
<pagerstyle backcolor= "#F7F7DE" forecolor= "Black" horizontalalign= "right" />
<selectedrowstyle backcolor= "#CE5D5A" font-bold= "True" forecolor= "white"/>
& Lt HeaderStyle backcolor= "#6B696B" font-bold= "True" forecolor= "white"/>
<alternatingrowstyle BackColor = "White"/>
</asp:gridview>
<asp:objectdatasource id= "ObjectDataSource1 runat=" serve R "Typename=" Stuwcfservice.wcfstudenttext "selectmethod=" getstudent "
</asp:objectdatasource>
;/div>
The advantage of Objectdatasourse is that you can invoke methods in the proxy class without writing a single line of code. What should be noted here is the typename,selectmethod of two important attributes, which must be consistent with the proxy class.