Archive for December, 2022
What Is Windows Communication Foundation(WCF)
Windows Communication Foundation (WCF) is a .NET framework for developing, configuring and deploying services. It is introduce with .NET Framework 3.0.It is service oriented technology used for exchanging information. WCF has combined feature of .NET Remoting, Web Services and few other communications related technology.
Key Feature of WCF:
- Interoperable with other Services
- Provide better reliability and security compared to ASMX web services.
- No need to make much change in code for implementing the security model and changing the binding. Small changes in the configuration will make your requirements.
Difference between WCF and Web service
Web Service | WCF |
---|---|
It can be hosted in IIS | It can be hosted in IIS, windows activation service, Self-hosting, Windows service. |
[WebService] attribute has to be added to the class and [WebMethod] attribute represents the method exposed to client
Example. [WebService] public class myService: System.Web.Services.Webservice { [WebMethod] }
|
[ServiceContract] attribute has to be added to the class and [OperationContract] attribute represents the method exposed to client
Example: [ServiceContract] public Interface InterfaceTest { [OperationContract] public class myService:InterfaceTest { public string Test() return “Hello! WCF”; }
|
Can be access through HTTP | Can be access through HTTP, TCP, Named pipes. |
One-way, Request- Response are the different operations supported in web service. | One-Way, Request-Response, Duplex are different type of operations supported in WCF. |
System.Xml.Serialization name space is used for serialization. | System.Runtime.Serialization namespace is used for serialization. |
Can not be multi-threaded. | Can not be multi-threaded. |
For binding it uses SOAP or XML | Support different type of bindings (BasicHttpBinding, WSHttpBinding, WSDualHttpBinding etc ) |
WCF Services has three important companent.
- Service Class – A WCF service class implements some service as a set of methods.
- Host Environment- It can be a application or a Service or a Windows Forms application or IIS as in case of the normal asmx web service in .NET.
- Endpoints –All the WCF communications are take place through end point.
Endpoints consist of three component Address, Binding and contract. They collectively called as ABC’s of endpoints.
Address: It is basically url address where WCF services is hosted.
Binding: Binding will describes how client will communicate with service.
Binding supported by WCF
Binding |
Description |
BasicHttpBinding |
Basic Web service communication. No security by default |
WSHttpBinding |
Web services with WS-* support. Supports transactions |
WSDualHttpBinding |
Web services with duplex contract and transaction support |
WSFederationHttpBinding |
Web services with federated security. Supports transactions |
MsmqIntegrationBinding |
Communication directly with MSMQ applications. Supports transactions |
NetMsmqBinding |
Communication between WCF applications by using queuing. Supports transactions |
NetNamedPipeBinding |
Communication between WCF applications on same computer. Supports duplex contracts and transactions |
NetPeerTcpBinding |
Communication between computers across peer-to-peer services. Supports duplex contracts |
NetTcpBinding |
Communication between WCF applications across computers. Supports duplex contracts and transactions |
BasicHttpBinding |
Basic Web service communication. No security by default |
WSHttpBinding |
Web services with WS-* support. Supports transactions |
Contract: The endpoints specify a Contract that defines which methods of the Service class will be accessible via the endpoint; each endpoint may expose a different set of methods. It is standard way of describing what the service does.
Mainly there are four types of contracts available in WCF.
- Service Contract: describe the operation that service can provide.
- Data Contract: describes the custom data type which is exposed to the client.
- Message Contract: WCF uses SOAP message for communication. Message Contract is used to control the structure of a message body and serialization process. It is also used to send / access information in SOAP headers. By default WCF takes care of creating SOAP messages according to service DataContracts and OperationContracts.
- Fault Contract: Fault Contract provides documented view for error occurred in the service to client. This help as to easy identity the what error has occurred, and where. By default when we throw any exception from service, it will not reach the client side.
Creating WCF service in visual studio 2013:
- First open Visual Studio 2013. Create a new project and select WCF Service Application and give it the name WcfService1.
- Delete default created IService1.cs and Service1.svc file.
- Right-click on the project and select “Add” | “New Item…”
- From the Web tab choose WCF Service to add.
- give the service the name “HELLO.svc”
- Open IHELLO.cs and remove the “void DoWork()”.
IHELLO.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace WcfService1
{
// NOTE: You can use the “Rename” command on the “Refactor” menu to change the interface name “IHELLO” in both code and config file together.
[ServiceContract]
public interface IHELLO
{
[OperationContract]
string sayHello();
}
}
- Configure Endpoints with Metadata
To do this open the Web.config file. We are going to create one Endpoint with basicHttpBinding. We are adding a Endpoint also to configure the metadata of the service.
<services>
<service behaviorConfiguration=”WcfService1.HELLOBehavior” name=”WcfService1.HELLO”>
<endpoint address=”” binding=”basicHttpBinding” contract=”WcfService1.IHELLO”/>
<endpoint address=”mex” binding=”mexHttpBinding” contract=”IMetadataExchange” />
</service>
</services>
- Implement Service. HELLO.svc.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace WcfService1
{
public class HELLO : IHELLO
{
public string sayHello()
{
return “Hello! welcome to WCF”;
}
}
}
Now we have created the Service and configured the Endpoint.To host it press F5 in Visual Studio.
In the browser you will see the Service as in the following. To view the metadata of the Service click on the WSDL URL.
In Windows / Web application we can consume this WCF service by using “Add Service Reference”->Add Service Address “http://localhost:57091/HELLO.svc” -> Click on Go.
I had created console application and added service reference.
Program.cs
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
HelloServiceReference.HELLOClient oHell = new HelloServiceReference.HELLOClient();
string str= oHell.sayHello();
Console.WriteLine(str);
}
}
}
Related helpful links
https://msdn.microsoft.com/en-us/library/ms731082(v=vs.110).aspx
I hope this will help you.Your valuable feedback and comments are important for me.
SharePoint 2016 Farm configuration issue on Windows Azure Virtual Machine
Hi All,
I hope you all know that now we can create a SharePoint 2016 VM on Windows Azure. In case you have not tried it yet, you can follow below:
Select New on Windows Azure > Compute > Virtual Machine > From Gallery > Select SharePoint from left hand navigation > Select SharePoint Server 2016 IT preview
While I was working with this VM, I came across an issue where I was unable to configure a SharePoint 2016 farm using the SharePoint 2016 VM created in Windows Azure using one of their template. I found that root of issue was Active Directory. SharePoint cannot work without active directory and not everyone using Azure creates a VM with AD in Windows Azure itself. If you plan to create an AD forest in Azure and then add SharePoint 2016 VM to that domain, please follow my article:
Creating a Lab on Windows Azure
http://blogs.msdn.com/b/mvpawardprogram/archive/2015/02/09/creating-a-lab-on-windows-azure.aspx
If you are planning to use this VM only for learning purpose then you may want to create a SharePoint farm without Active Directory. Unlike previous versions of SharePoint, you cannot use Single Server install model to create a SharePoint farm without Active Directory or without installing SQL server.
To overcome this issue you need 1st install SQL Server and then use below PowerShell command to configure your SharePoint farm. You can download SQL server from below link
https://www.microsoft.com/en-in/download/details.aspx?id=42299
Once SQL server is installed and your local admin account has access to SQL server, you can use SharePoint PowerShell to create tour SharePoint 2016 Farm.
1. Open SharePoint PowerShell as Admin
2. You may want to type below command and provide actual values. When you execute the command, you will be requested for credentials of your local admin account you used while creating this Virtual Machine.
New-SPConfigurationDatabase -DatabaseName “SP2016_config” -DatabaseServer “Name of SQL Server” -Passphrase (ConvertTo-SecureString “Sharepoint@2016” -AsPlainText -force) -LocalServerRole SingleServerFarm -FarmCredentials (Get-Credential)
Note: I have observed that when people try to copy paste such commands, hyphen(-) sign does not work, so remove and add these sign again in whole command.
Once above command is executed successfully without any issue, you can execute SharePoint PSconfig wizard and complete SharePoint farm configuration.
Hope this will help you.
SharePoint site down “An application error occurred on the server” web.config error
Hi All,
Recently I got below error message which you might have seen. This is a very common and generic error message which can confuse you a lot. You may face this issue in all versions of SharePoint like SharePoint 2007, 2010, 2013 or SharePoint 2016. First let us look at the error message
#################### Error Start #############
Runtime Error Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be view able on remote machines, please create a <customErrors> tag within a “web.config” configuration file located in the root directory of the current web application. This <customErrors> tag should then have its “mode” attribute set to “Off”.
<!– Web.Config Configuration File –>
<configuration>
<system.web>
<customErrors mode=”Off”/>
</system.web>
</configuration>
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the “defaultRedirect” attribute of the application’s <customErrors> configuration tag to point to a custom error page URL.
<!– Web.Config Configuration File –>
<configuration>
<system.web>
<customErrors mode=”RemoteOnly” defaultRedirect=”mycustompage.htm”/>
</system.web>
</configuration>
#################### Error End #############
We can see that error message says something about web.config file. Here is what we need to do.
1. Open IIS management console
2. Start > RUN > Inetmgr > Expand server
3. Expand the site you are getting this error on > right click > explore
Here you should be able to see a web.config file. If this web.config was recently modified by someone, please check with your team if anyone has recently modified this file, tried to deployed a farm\web application solution or run psconfig wizard on any of the SharePoint server in farm.
Note: If you have multiple SharePoint server, try the same on all the servers
In most cases, it is a web.config change done by someone from within the team which cause this issue.
If no one has done any changes:
1. Make a copy of this web.config file and open the original file. Search for “callstack” and set the value to True, again search for customerrors set it to OFF.
2. Rename the recent web.config to web.config.old with today’s date and revert the most recent web.config(date and time) file to web.config
3. Install Examdiff tool on a computer and copy the most recent web.config file and new web.config to identify the changes.
These steps will help you identify the actual cause of this error.
Myth Buster for SharePoint SQL RBS
Hi All,
In this article I would try to share my experience about SharePoint on SQL RBS. This article may help you decide if you should use SQL RBS with SharePoint or any other product.
This is my personal opinion about SQL RBS with SharePoint. I would suggest you to cross check below furnished details before taking final decision. Microsoft keeps enhancing its product so some of these may be fixed\resolved\changed.
Let’s first discuss what is SQL RBS? Normally when you upload a document, image, video, audio, etc on your SQL server it is stored in MDF (Master database file) of your SQL content database. As per my past experience when you upload anything to a content management system, you would revisit only 20 % of data uploaded, rest 80 % of data is never visited but used for record only purpose. IT pro’s suggest that you should keep your SQL content database on RAID 10 hard disk or SAN which is pretty expensive.
To resolve this issue Microsoft came out with SQL RBS which allows you to store your Files\BLOB outside (File system) of SQL database. This means you can use a Raid 0 drive to store BLOB files (image, video, document, etc). RBS is intended to lower storage costs by allowing you to store large read-intensive BLOBs on less expensive drives.
1st Myth of SQL RBS: Additional Storage for Content database.
This is the biggest myth about SQL RBS. Microsoft Suggest that your content database should be below 200 GB. Now days when we have a USB stick with 100 GB, a Content management server restricted to 200 GB is not a good deal. To overcome this issue few IT admin plan to use SQL RBS because RBS stores files outside of SQL server hence decrease the size of content database.
Reality: RBS does not increase the storage limits of content databases. All limitations still apply to RBS-enabled content databases. If you are using Remote BLOB Storage (RBS), the total volume of remote BLOB storage and metadata in the content database must not exceed the 200GB limit.
2nd Myth of SQL RBS: Files stored on FILESYSTEM through RBS cannot be accessed directly.
IT Pros and lot of other articles says that we cannot open the file directly from BLOB FILESYSTEM. We have to go through SQL database in order to read these files.
Reality: I was able to access FILESYSTEM where the BLOB files were stored and was able to open my txt, bmp, jpg, etc files. SharePoint is known for its Item level Security. So far SharePoint security was never compromised and access is only available on need to know basis. If any users who has access to FILESYSTEM can open any file stored in SharePoint without having access on SharePoint is a security issue. Also encryption is not supported on BLOBs, even if Transparent Data Encryption is enabled.
3rd Myth of SQL RBS: Better performance I hear a lot of IT PRO who comment that they would get better performance if FILES\BLOBS are stores outside of SQL Server.
Reality: I would accept this when we are using SharePoint to store Hugh amount of data files (70-80 % of BLOB). When I asked these IT Pros how much data is stored on dbo.docs, dbo.AllDocStreams, dbo.DocStreams, dbo.AllDocVersions, dbo.alldocs, etc table, they are not aware of same or they don’t bother. When you offload 70-80 % of data from your MDF file and store it FILESYSTEM you may feel better performance. If our content database stores BLOB files not more then 30-35 % then it would not make sense to go with RBS. Let me explain you why I say that, when you configure RBS you create number of additional tables on your content database. This means when we upload BLOB to SharePoint it will execute additional query to store data. Here SQL will first import image files, and then it may split the file based on size of file and then store it to FILESYSTEM. Again this process is reversed when we try to open or query the BLOB file. This will increase disk IO, RAM and processing power. Now if consumption of my resources is increased, how can I expect better performance? RBS does not support using data compression but data is compressed when uploaded to SQL MDF file. Microsoft says “Although using RBS with files larger than 1 MB can improve I/O and processor performance, using RBS with files smaller than 256 KB might decrease overall performance. Storing the BLOBs inline in the content database is more efficient with smaller files”
4th Myth of SQL RBS: Ease in management
A lot of IT Pro’s also comment that it is easy to manage smaller SQL databases, Better Technology, Ease in configuration, etc.
Reality: Why you want to take an additional Load of configuration anything extra on SQL. If any feature is available does not mean you should use it. Implementation of these features depends on its pros\cons and specific requirement of the feature. Also when you backup the database, it will backup all the files from FILESYSTEM along with SQL MDF\LDF files. Sizes of these databases backup does not decreases but it increase because RBS does not perform any compression. If you plan High availability through Mirroring or Log shipping, you need to follow additional steps to configure the same.
That’s it from my side. Feel free to comment or connect with me if you feel any of the above information is incorrect.
Reference:
https://technet.microsoft.com/en-us/library/cc262787.aspx
https://technet.microsoft.com/en-us/library/ff628583.aspx