This article is meant as a tutorial for using a logging tool for a WcfServices that looks to the outside world as an old WebService. (Pardon the namespaces, they have been changed to protect the innocent.)
WcfService that acts like a WebService
What I’ve used to do in the past is just add a WCF Service Library to the solution, and make sure binding="basicHttpBinding" is done. This way other platforms and applications could access the service like add web reference that looks something like http://localhost/WebService/WebService.OrderService.svc?wsdl. Why you want to do this? You want to take advantage of what you get in WCF, but still are able to act like a WebService to others that can’t implement WCF Service Reference. Everything else is like standard WCF, [ServiceContract], [OperationContract], [DataContract] and [DataMember] etc.
WcfService that acts like a WebService, but really is a Web Application
Another way of doing this is add a Web Application, strip out all that you don’t need. Like delete Default.aspx*.But instead of adding a new WCF Service, add an ordinary class, and then rename to whatever.svc. And remove all content, and replace it with these few lines:
<%@ ServiceHost Service="Services.OrderService" %>
This service reference should of course map to a class in your solution, probably the business layer. Make sure you add a reference. The business layer would then need a reference to System.Servicemodel to be able to add the needed attributes:
[ServiceBehavior(Namespace = "http://brembo.name/namespace/workorder")]
public class OrderService : IOrderService
…
[ServiceContract(Name = "OrderService", Namespace = "http://brembo.name/namespace/workorder")]
public interface IOrderService
The web.config would only need these lines (remove everything else):
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="Services.OrderService" behaviorConfiguration="DebuggingBehaviour">
<endpoint address="" binding="basicHttpBinding" bindingNamespace="http://schema.brembo.name/" contract="Services.IOrderService"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DebuggingBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<appSettings/>
<connectionStrings/>
</configuration>
The Web Application contains by default many no longer needed references. These are the only one needed: System, System.Core, System.Data, System.Runtime.Serialization, System.ServiceModel. Also add your business layer.
If you like to remove the App_Data folder which isn’t needed, unload project, edit project file and remove these lines:
<itemgroup>
<folder include="App_Data\">
</itemgroup>

No comments:
Post a Comment