If you are ASP.NET programmer then you already know about Server.MapPath. It is used to map a physical location on webserver for asp.net. You can find more information about Server.MapPath from the following location.
http://msdn.microsoft.com/en-us/library/ms524632(v=vs.90).aspx
You can still use that in WCF(Windows Communication Foundation) service http bindings. As we know WCF Service can use other non http bindings like TCP/IP,MSMQ and Named Pipe. At that time HttpContext of WCF will be none so server.mappath will not be available as current context is not available. Because its a child class of HttpContext.Current.
Showing posts with label WCF. Show all posts
Why sometimes it’s not a good idea to use session variables in class library project.
As we all know web pages are stateless pages and we need to use session variables in web application to maintain some session over page. Some time we divide our application into multiple layers for example business logic layer,database layer etc. This all layers will be a class library projects.
So when you have your applications divided into the multiple layers at that time you might need to use session variables in the class library projects. For that we are adding System.Web namespace as a reference to a class library project and then we can use session with HttpContext object. That’s works fine if your layers are going to be used in web application projects. But for example if you have service oriented architecture and your services also access your class libraries via non standard protocol i.e. WCF Service hosted on TCP/IP bindings. At that time sessions will not work.
Instead of that you should always use the parameters in method and avoid direct use of session variables. That parameters will passed either from the web application or from the services which is calling the class libraries.
Hope you liked it. Stay tuned for more..
How to create overload methods in WCF service with C#
So let’s consider same Hello world example which we have used web service overload method. Let’s create two methods HelloWorld one is with name and another is without parameter. For WCF service we have to first create interface following is a code for that.
Request format is unrecognized for URL unexpectedly ending exception in web service.
Recently I was getting error when I am calling web service using Java script. I searching on net and debugging I have found following things.
Any web service support three kinds of protocol HttpGet,HttpPost and SOAP. In framework 1.0 it was enabled by default but after 1.0 framework it will not be enabled by default due to security issues and WS-Specifications. So we have to enabled them via putting configuration settings in web.config. Here is the code for that.
<configuration>Hope this will help you. Stay tuned for more. Till that Happy programming!!!.
<system.web>
<webservices>
<protocols>
<add name="HttpGet"></add>
<add name="HttpPost"></add>
</protocols>
</webservices>
</system.web>
</configuration>
Technorati Tags: WebService,Request,Javascript,Ajax
Difference between Web Service and WCF Service
While taking interviews of .NET developers I often ask this questions. But lots of people don’t know exact difference between this. So, I decided to write a separate blog about this.
Here are the few differences.
- Web services can be hosted in IIS as well as outside of the IIS. While WCF service can be hosted in IIS, Windows activation service,Self Hosting,WAS and on lots of proctols like Named Pipe,TCP etc.Here lots of people disagree how we can host the web service outside of the IIS but Here is the article for that.http://msdn.microsoft.com/en-us/library/aa529311.aspx.
- In Web Services Web Service attribute will added on the top of class. In WCF there will be a Service Contract attributes will be there. Same way Web Method attribute are added in top of method of Web service while in WCF Service Operation Contract will added on the top method.
- In Web service System.XML.Serialization is supported while in the WCF Service System.RunTime.Serialization is supported.
- WCF Services can be multithreaded via ServiceBehavior class while web service can not be.
- WCF Services supports different type of bindings like BasicHttpBinding, WSHttpBinding, WSDualHttpBinding etc.while Web services only used soap or xml for this.
- Web services are compiled into a class library assembly. A file called the service file is provided that has the extension .asmx and contains an
@ WebServicedirective that identifies the class that contains the code for the service and the assembly in which it is located while in WCF.WCF services can readily be hosted within IIS 5.1 or 6.0, the Windows Process Activation Service (WAS) that is provided as part of IIS 7.0, and within any .NET application. To host a service in IIS 5.1 or 6.0, the service must use HTTP as the communications transport protocol.
Hope this will help you. Happy programming!!!

