Navigation:(1) The journey to WCF
(2) Solution to the Problem of WCF port number
(3) applications cannot be found when WCF adds service references.
(4) source of service reference in WCF
Q: to add a service reference in WCF, you need to find the service through an address, as shown in the following code:
At the beginning, I was wondering how to find this name (appointmentserviceimepletation) in the service? Where can I define the service name?
I thought about it carefully. In fact, this name is found through the namespace + class name. It has already been set in the configuration file when defining the service:
1 <? XML version = "1.0" encoding = "UTF-8" ?>
2 < Configuration >
3
4 < System. Web >
5 < Compilation Debug = "True" Targetframework = "4.0" />
6 </ System. Web >
7 < System. servicemodel >
8 < Services >
9 < Service Behaviorconfiguration = "Appointmentserviceiishost. servicebehavior"
10 Name = "com. contoso. appointmentservice. appointmentserviceimplementation">
11 < Endpoint Binding = "Wshttpbinding" Bindingconfiguration = "" Name = "Wshttpbinding"
12 Contract = "Com. contoso. appointmentservice. appointmentservicecontract" />
13 </ Service >
14 </ Services >
15 < Behaviors >
16 < Servicebehaviors >
17 < Behavior Name = "Appointmentserviceiishost. servicebehavior" >
18 < Servicemetadata Httpgetenabled = "True" />
19 < Servicedebug Includeexceptiondetailinfaults = "False" />
20 </ Behavior >
21 </ Servicebehaviors >
22 </ Behaviors >
23 < Servicehostingenvironment Multiplesitebindingsenabled = "True" />
24 </ System. servicemodel >
25 < System. Webserver >
26 < Modules Runallmanagedmodulesforallrequests = "True" />
27 </ System. Webserver >
28
29 </ Configuration >
The most obvious line is our previous definition. When adding a service reference, only the name is displayed. This class is defined in the agreed class.
1 NamespaceCom. contoso. appointmentservice
2{
3Public ClassAppointmentserviceimplementation: iappointmentservicecontract
4{}
5}
Now I know a little about the principle, but how can I use this reference?
Before that, my service has been written, and the running effect is good:
Execute svcutil.exe according to the method displayed on this page. Two files will be automatically generated: appointmentserviceimplementation. CS and output. config, which are the same as the preceding service description, and then you can call them at the client!