Important Points of WCF Service

WCF Service

This article explains some points about WCF services. I believe we should understand these points and their implementation also. The main intent to write this article is for those people who don't understand the exact utilization of keywords and settings during WCF service creation and hosting.


image1

I have created a sample WCF service library and implemented an interface having a method Get info. Kindly refer to the image below for the basic structure of the web site:

add WCF service library

Note that in the image shown above, I have also hosted this WCF service using a console application.

The main intent to write this article starts from here. I host this application and the edit app.config file using "Edit WCF configuration". Kindly see the image shown below:

edit WCF configuration

The image below shows the layout of the app.config file.

layout of app config

Note

Thus in order to generate proxies, you need metadata information. When you remove the serviceMetadata-line you say you are not providing Meta data in WSDL format. But the line before, publishing your metadata in MEX, is still active, thus you can generate a proxy from those metadata. When you provide neither WSDL nor MEX formatted information, you cannot generate a proxy.

Now let's execute the procedure shown above more practically.

Point 1

Point 1

The WCF service is up and running as shown in the image below:

WCF service is up and running

Initially service metadata is enabled as shown below:

service metadata is enabled

I just paste a baseAddress URL into the browser, it provides us metadata in WSDL format as shown in the image below:

metadata in wsdl format

But if I change it to "false" then it doesn't provide you metadata in WSDL format. Kindly refer to both images as shown below:

service metadata  false 

metadata in wsdl format false

Point 2

Point2 

Now let's understand why mexHttpBinding is important from a WCF perspective.

I've disabled the "mexHttpBinding" code segment and host our service. It prompts us an error at the time of adding a Service reference to the Client application.

disabled mexHttpBinding

The "IMetadataExchange" contract is for enabling metadata for the service. This is required for adding the service reference at the WCF client-side or it is a binding that returns metadata so you can build a proxy at the client side.

MEX endpoints are special endpoints that allow clients to receive the service's metadata using SOAP messages instead of HTTP get requests. You can create MEX endpoint that can be accessed through HTTP, HTTPS, TCP and even named pipes.

Point 3

Point 3

The third point is about enabling the logging/tracing process in the client application so that I can see what happened at the time of calling an operation of the WCF Service.

I've created a client application and added a reference of WCF Service, kindly see an image show below:

added a reference of WCF Service

To enable logging and tracing in the client application edit the app.config file. Kindly see the following image.

edit app.config file

Go to Diagnostics and enable Log Auto Flush, MessageLogging and Tracing. Kindly see the image shown below:

Go to Diagnostics

Now go to "Diagnostics" -> "Message Logging" and set the properties to true as shown in the image below to log the exact information.

Message Logging

After setting the properties to true it asks you to update your app.config file, press yes to all. And go through once with the updated config file. Now we are done with all the requirements and ready to consume our service via the client. Press F5.

It will be the first appearance of the client application as shown in the following image:

first appearance

I put some value in the text box and pressed on the GetInfo button, see the result below.

put some value

Now look at the .svclog files that exist in the root folder of the client application as shown in the image below:

svclog files

Note

Don't forget to refresh this folder once.

Double-click on the app_messages file and see the result.

Double click on the app_messages

Response

Response

I believe we learned remarkable points about WCF services, that we may encounter in daily routine work.

You can also have a look at MVC-related articles here:


Similar Articles