Endpoints, endpoints and endpoints. Here we will cover some different ways you can configure the endpoints for your services.
Here we will discuss how to configure the service endpoints for different forms of communications. As discussed in the previous post on WCF, configurations are managed through the app.config for the service project. In the previous post, we have seen how we can right-click on the app.config and then click on ‘Edit WCF Configuration’ to configure your service, endpoints and behavior.
If we were to examine the app.config by opening it as an XML document, we will find that after completing the last exercise, we have 2 endpoints. One for the basic http deployment and the other for the metadata exchange.
Each endpoint has three attributes associated with it.
v Address – the network address, where is the service located
v Binding – how are we going to communicate with the service such as transport and WS* protocols
v Contract – describes what the message must provide and contain (types and operations).
Below the endpoints definition, in the app.config there is also a <host><baseAddresses><add baseAddress=”….”>… defined that is the base address for all our services that have been defined. The address attribute of an endpoint simply gets added to the base address.
You can add additional endpoints, such as those using another communication protocol such as TCP or Named Pipes, to your service through the Microsoft Service Configuration Editor Dialog box, after you have deployed your service. You can even make these changes directly in your app.config.
Configuring Service Behaviors
We can add different behaviors to our services. For instance you can expose the WSDL / metadata of your service through a Http Get operation by enabling that behavior.
1. Create the behavior. In the Microsoft Service Configuration Editor Dialog box, Advanced, Service Behaviors and adding or editing an existing behavior. I have marked the HttpGetEnabled to True, provided a URL for the HttpGetUrl attribute and named it Metadata.
2. Use the behavior. Now in the Services node, I locate the service and provide the behavior called Metadata to the BehaviorConfiguration attribute and saved the dialog box.
3. Upon hosting the service, the WSDL will now be available at the URL provided in Step 1 above. A client can then generate a proxy from this WSDL.
Configuring Service Bindings
We can also configure bindings for our services to support the various WS* extensions such as Security, Reliable Messaging, etc. To do this, the easiest way is to use the Microsoft Service Configuration Editor Dialog box, go to the Bindings node, right-click and add or edit the appropriate binding and then go to your service endpoint, and in the General pane on the right, associate the binding configuration you just created for the BindingConfiguration attribute.
Hosting your service in IIS
1. Start by adding a new Web Site project to the solution.
2. Choose the WCF Template and we’ll call it the GetCurrentTimeSite
3. Now, delete the Service.cs and IService.cs from the newly created Web Site project and Add a REFERENCE to the web service project.
4. This will add the service library dll in the Bin directory.
5. Next rename the Service.svc to something more meaningful such as GetCurrentTime.svc
6. Next edit the .svc file and change the Service attribute to the fully qualified name, in our case, TutorialService.CurrentTimeService
7. Further, delete the codebehind attribute and its value.
8. Now, we need to configure the service and its endpoint(s). Launch the web.config Microsoft Service Configuration Editor Dialog box for the web site,
9. For the Services node, click on Create a new Service and provide it the service implementation and the contract interface by browsing to the dll in the Bin folder from within the wizard.
10. Now test this out by right-clicking on the .svc file and selecting View in Browser.
11. You will see the documentation for the newly created service in a browser window.
12. To test, go to a command prompt and type in> wcftestclient [address of the service from the documentation. should end in .svc]
13. If all works well, go to the IIS management tool and create a new application under one of the sites.
14. Now map this new application to a physical path of the service site (GetCurrentTimeSite) in our case.
15. Now your service should be available, hosted within IIS.