Few lines about WCF metadata
Dec07

Few lines about WCF metadata

What is WCF metadata? WCF generates metadata for service endpoints and this metadata is used to describe how to interact with the service’s endpoints. This information is used by Svcutil.exe to generate proxy for accessing the service. WCF metadata is exposed by one or more metadata endpoints similar to service endpoints. They have an address, a binding, and a contract. This information is sent over standard protocols, such as WS-MetadataExchange (MEX) and HTTP/GET requests. Also, Metadata can be added to a service host through configuration or imperative code. We can see the below example for adding metadata endpoints to the service in the configuration file. <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> What are the bindings available for Service Metadata?  mexHttpBinding for HTTP protocol.  mexHttpsBinding for HTTPS security layer.  mexNamedPipeBinding for named pipe.  mexTcpBinding for TCP protocol. Can Service Metadata be tampered? Service metadata can be tampered with or spoofed. Spoofed data can be used to redirect client to a malicious service. Metadata documents can be large and are frequently saved to the file system. How to protect Service Metadata? Use a secure binding to request service metadata. Publish service metadata over HTTPS, use mexHttpsBinding and configure a server certificate for the...

Read More
Difference Between Transport and Message Security in WCF
Dec06

Difference Between Transport and Message Security in WCF

Transport Security in WCF As the name suggests, it is concerned with security of communication between client and the service over a network protocol. It guarantees the confidentiality and integrity of messages at transport level. Transport security is required for point-to-point security between the two endpoints and is dependent on the transport [protocol] being used. The simplest approach is to encrypt and send it over HTTPS protocol. To encrypt/sigining the contents, Secure Sockets Layer(SSL) is used. Note: Transport security is available on all of the bindings except for wsDualHttpBinding. Example <bindings> <wsHttpBinding> <binding name="SecureWsHttpBinding"> <security mode="Transport"> </security> </binding> </wsHttpBinding> </bindings> Message Security in WCF As the name suggests, it is concerned with security of message between client and the service. It is not dependent of the network protocols. It guarantees the confidentiality and integrity of the messages at the message level. Message security ensures encryption and signing of the messages. Note: Message security is available on all of the bindings except for netNamedPipeBinding and MSmqIntegrationBinding. <bindings> <wsHttpBinding> <binding name="SecureMessageBinding"> <security mode="message"> </security> </binding> </wsHttpBinding> </bindings> Media, on any given day,is a better way of conveying 1000s words of explanation so below are two images taken from msdn which perfectly shows the differences. Ref:MSDN Just concentrate on the locks of XML file being transmitted and the transport channel being...

Read More
Caching in WCF Services
Oct08

Caching in WCF Services

Yes, It is possible and clearly a  significant performance enhancement. How caching works for WCF services? Lets assume, a user sends a request to a service so at server, service method is called and response is sent back to the user. Now, when we configure caching at service, then the service method is not called, instead a cached response is sent back. If the cache expires, the next time service method is called and the response is again cached. How caching is implemented in WCF services? 1) Mandatory Configuration: Enable ASP.NET compatibility mode in the Web.config file <system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> </system.serviceModel>  2) Attach a Cache Profile: Cache Profile settings are maintained in web.config under system.web settings <outputCacheSettings> <outputCacheProfiles> CustomCache" duration="120" varyByParam="none" /> </outputCacheProfiles> </outputCacheSettings> Attributes of the cache profile are: Duration and varyByParam Duration: Time duration for which the response is cached. varyByParam: Separate cached responses for different query parameters. 3)  AspNetCacheProfile attribute First, Enable AspNetCompatibilityRequirementsAttribute and set RequirementsMode to Allowed or Required. The default value is NotAllowed. This attribute is applied to a service so that the service can run in ASP.NET compatibility code. Next, Apply AspNetCacheProfileAttribute to a service operation. This attribute specifies a cache profile name. In our case, Cache profile name is “CustomCache” which we declared in web.config earlier. [ServiceContract] [AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)] public class CalculatorService { [WebGet(UriTemplate = "?num={num}")] [AspNetCacheProfile("CustomCache")] public int Calculate(int num) { // Do Calculation. } } More: There is more to caching like SQL Cache Dependency. WCF service may depend on data stored in a SQL database so when data in the SQL database table changes, it may require to recreate the...

Read More
REST- REpresentational State Transfer
Apr13

REST- REpresentational State Transfer

REST – REpresentational State Transfer, is an enhanced version of client server style architecture for distributed communication. When we talk about distributed communication, we think of request and response. A request is something which is made by client to a server and in reply, response is sent back by the server to the client. What’s new in this? Nothing!! REST brings the ‘new’ thing. This ‘new‘ thing is ‘transfer of representations of resources ‘ There are three main keywords ‘transfer’, ‘representations’ and ‘resources’. We already know the meaning of ‘transfer’ as we are talking about distributed communication. A ‘resource’ can be any object on server like a document, an image, flash etc. When client request a resource, it receives a ‘representation’ of that resource. A ‘representation’ is the current state of the resource. How is REST an enhancement over WCF/Webservices? For more info on WCF, refer this link, we will take an example to understand the enhancement more clearly. Suppose we have a service which maintains data of weather forecast and at client side, a proxy of this service is created where client will consume this service through the proxy by calling a method like GetTodayForecast() which will send today’s forecast data from server to client. REST came out with noun based approach where the same method is called but with the help of URI which is referred to as noun-based approach. This URI might look like https://localhost/TodaysForecast Latter part of this URL ‘TodaysForecast’ is the resource in which the client is interested. This will play the role of representation of an object ‘forecast’. The best part which I personally like is in REST, there is NO need of creating a proxy. We just need to wrap the request with HTTP verbs – GET, PUT, POST, and DELETE and the response can be an XML or JSON. We will go through these HTTP verbs also to get more insights. HTTP verbs GET – GET request as the name implies will request the server for a particular resource. For example:-We might need to have forecast details of some particular day. http://localhost/ForeCastService/forecast/day/1. This HTTP request will be received by server and GetTodayForecast() method will get executed. In response, client will receive a XML or JSON response as configured. POST – The POST method is used to create a new resource or update the existing one. http://localhost/ForeCastService/updateforecast Client will send this request with an updated object ‘forecast’ to server. In response, server will send a response notification like success or fail. PUT – We always get confuse between POST and PUT as both behave the identical way then what is the difference?...

Read More
WCF Part 3: Direct from WCF kitchen.
Dec22

WCF Part 3: Direct from WCF kitchen.

In the last two articles WCF:Part 1 and WCF Part 2, we have covered basic knowledge and terminologies of WCF.Now we will apply that knowledge to create a WCF service.There are lot of articles available on internet related to creating a WCF service but the knowledge gap is still there. Let’s try to fill this gap today. As a good chef, before making your WCF curry, please make sure you have following ingredients available in your kitchen. Visual Studio 2008 or above Windows SDK IIS .Net Framework 3.0 or above WCF templates We will follow these steps to create our WCF curry. In between, we will surely include our commentary to provide more insights. Create a new Solution and Project. Choose WCF Service Library Template. Create the Service and Operation Contracts. Implement Service and Operation Contracts. Changes in App.Config. Test the Service. Create a new Solution and Project: Launch Visual Studio 2008. Click on File -> New –> Project “New Project” window will appear. On the Left hand side, Project types are available, choose WCF. Here, we select WCF Service Library and provide the Name and Location to the project. We gave Name as “CalculatorService”.On Click of OK, We will have the solution and project created Note:There are a few built-in WCF service templates; two of them are Visual Studio WCF Service Library and Visual Studio WCF Service Application. In this article, we will use the service library template. On the Right Hand side, we see “IService.cs” and “Service.cs” available. These are the default file created by the project with some default code in them. Please note that, if you rename these files, change the reference everywhere in the project or else solution will not compile. Create Service Contract and Operation Contracts: Open IService.cs and same screen as above will appear. Here, we have to define service contracts and operations contracts. For more information about contracts, read WCF Part 2 We have renamed “IService.cs” as “ICalculator.cs” and also replaced Service contracts with ICalculator. We have removed older Operation contracts and replaced them with new Operation contracts as Add(int num1, int num2) and Subtract(int num3,int num4) method definitions. As we are using .Net types so there is no need to define Data Contracts here. For more information about data contracts, read WCF Part 2. Implement Service Contract and Operation Contracts: Rename Service.cs as something relevant like Calculator.cs . This file is used to implement contracts. I suggest looking at the code will be much more beneficial. Now, build this solution. If the build is successful means there is no issues and service is ready to be served to the external...

Read More
Page 1 of 212