Source of service reference in WCF

Source: Internet
Author: User

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!

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.