Hi,
Here is the final version of my WCF integration. Attached :
- The patch for the latest SVN release
- A short documentation
Please give me your comments.
Next steps:
- Better exception handling
- Use host factories
- Server as Windows Service
- Debugging :-)
I hope this thread will be more successful as the previous one !
-------------------------------------------------------------------------------------------
1 WCF Server
The WCF server is supposed to be hosted in IIS. It is composed of *.svc files that enable to expose the “Service” layer of .netTiers to WCF and a Web.config file that enables to configure the service.
The configuration files are samples and are meant to be customized, but they work “out-of-the-box” for a simple un-secure WCF integration.
<service name="NameSpace.Services.ItemService" behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="BindingConf" contract=" NameSpace.Services.IItemService" />
</service>
In order to retrieve large objects from WCF, the following had to be activated:
<basicHttpBinding>
<binding name="BindingConf" maxReceivedMessageSize="67108864" /> </basicHttpBinding>
The endpoints need interfaces to expose the services. As a consequence, .netTiers templates for the Service (eg: Component) layer are customized to add the proper interfaces on generation.
If you want to expose a new method, then you must declare it in the interface, with a unique name. Sample:
[OperationContract(Name="HelloWorld")]
string HelloWorld();
2 WCF Client
The WCF client is composed of:
- Sample configuration files (App/Web.config and entlib.config)
- A proxy factory
The proxy factory enables to connect either using WCF of directly to the database, by changing the parameter communicationPlatform in the *.config file. When using Direct mode, the classic .netTiers configuration must be added.
3 Testing
- Run NetTiers templates and activate WCF library generation.
- Open generate solution in Visual Studio.
- Compile and check for errors (hopefully none).
- Server
- Create a new virtual host in IIS
- Point the directory to the Namespace.WCF/ folder
- Activate ASP.NET 2.0 (does not work with 1.1)
- Go to the URL of a service and check the wsdl is valid.
- Client
- Create a new Console Application project
- Copy Web.App.sample.config from the WCFClient project and name it App.config
- Copy entlib.sample.config from the WCFClient project and name it entlib.config. Check “copy always” in the file properties
- Add references to the .netTiers projects and to the EntLib dlls.
- Add some simple code to check your WCF service is working. Sample:
try
{
NameSpace.Services.IItemService service = NameSpace.WCFClient.ProxyFactory.ItemServiceProxyInstance();
foreach (NameSpace.Entities.Item Item in service.GetAll())
{
Console.WriteLine(Item.ToString());
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.ReadLine();