Points to remember: WCF Service
In this article I will explain some points about WCF service believe we should understand those points and their implementation also.
The main intent to write this article for those people who doesn’t understand the exact utilization of keywords and settings during WCF service creation and hosting
.
I have created a sample WCF service library and implement an interface having method Get info. Kindly refer an image depicted below for basic structure of web site:
If you notice an image shown above, I have also hosted this WCF service using console application.
Main intent to write this article starts from here.When I host this application and edit app.config file using ‘Edit WCF configuration”. Kindly see an image shown below:
This is a layout of app.config file as shown in image below.
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 shown above steps more practically.
WCF service is up and running as shown in image below:
Initially service metadata is enabled as shown below:
I just paste a baseAddress url in browser, it provides us metadata in wsdl format as shown in image below:
But if I change it to “false” than it doesn’t provide you metadata in wsdl format. Kindly refer both images as shown below:
Now lets’ understand why mexHttpBinding is important from WCF perspective.
I’ve disabled “mexHttpBinding” code segment and host our service. It prompts us an error at time of adding Service reference to Client application.
‘IMetadataExchange’ contract is for enabling metadata for the service. This is required for adding service reference at 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 by 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.
Third point is about to enable logging/tracing process in client application so that I could see what happen at time of calling an operation of WCF Service.
I’ve created a client application and added a reference of WCF Service, kindly see an image show below
To enable logging and tracing in client application edit app.config file. Kindly see below depicted image.
Go to Diagnostics and enables Log Auto Flush, MessageLogging and Tracing. Kindly see an image shown below:
Now go to Diagnostics-> Message Logging and set properties to true as shown in image below to log the exact information.
After setting properties to true it asks you to update your app.config file, press yes to all. And go through once with updated config file. Now we are done with all requirements and ready to consume our service via client. Press F5.
It will be first appearance of you client application as shown below in image:
I put some value in text box and press on GetInfo button, See the result below.
Now look at the .svclog files exist in root folder of client application as shown in image below:
Note: Don’t forget to refresh this folder once.
Double click on the app_messages file and see the result.
Response:
GreatJ .
I belief we learnt remarkable points about wcf service, which we may face in daily routine work.
You can also have a look at MVC-related articles here:
- Smart Working With Custom Value Providers in ASP.Net MVC
- Invoke Action With Model Binders in MVC
- Extension Helpers Method in MVC
- Custom Button With TagBuilder Using MVC Razor Engine
- Precompiled Razor View Using RazorGenerator MVC and PreCompiledViewEngine in MVC 4
- Exception Handling at Filter Level Using IExceptionFilter in MVC4
- Practical Usage of TempData and ViewData and Differences in MVC 3
Keep coding and Smile
This comment has been removed by a blog administrator.
ReplyDelete