Here at work, we developed the SOAP WCF API, which can be accessed externally. Since one of the API requirements has changed, I wanted to add a new class to this API to create the correct paths for specific function calls.
Our API is divided into 3 separate libraries:
- One for objects
- One for interfaces
- One to implement.
The the course clients get the first two to work in scripts, the server has all three.
The class I want to add to the API is as follows:
namespace TenForce.Execution.API.Objects.Helpers
{
public interface IPathHelper
{
string ApplicationFolder { get; }
string CompanyHomeFolder { get; }
string CustomFolder { get; }
string WikiFolder { get; }
string AddinsFolder { get; }
}
}
The actual implementation of the class looks something like this:
using System.IO;
using System.Runtime.Serialization;
using TenForce.Execution.BUL;
using TenForce.Execution.Framework;
namespace TenForce.Execution.API.Implementation.Helpers
{
[DataContract]
public class PathHelper : Objects.Helpers.IPathHelper
{
#region Private Fields
private readonly ParameterBUL _mParameterBul;
private const Parameter.ParameterId DataHomeFolderId = Parameter.ParameterId.DataHomeFolder;
private const Parameter.ParameterId CompanyNameId = Parameter.ParameterId.CompanyName;
#endregion
#region Constructor
public PathHelper()
{
_mParameterBul = new ParameterBUL();
}
#endregion
#region IPathHelper Members
[DataMember]
public string ApplicationFolder
{
get
{
return CreatePath(_mParameterBul.GetParameterValue(DataHomeFolderId));
}
}
[DataMember]
public string CompanyHomeFolder
{
get
{
return CreatePath(Path.Combine(ApplicationFolder, _mParameterBul.GetParameterValue(CompanyNameId)));
}
}
[DataMember]
public string CustomFolder
{
get
{
return CreatePath(Path.Combine(CompanyHomeFolder, @"custom"));
}
}
[DataMember]
public string WikiFolder
{
get
{
return CreatePath(Path.Combine(CompanyHomeFolder, @"wiki"));
}
}
[DataMember]
public string AddinsFolder
{
get
{
return CreatePath(Path.Combine(CompanyHomeFolder, @"addins"));
}
}
#endregion
#region Private Members
private static string CreatePath(string path)
{
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
return path;
}
#endregion
}
}
All this is pretty simple stuff. We dynamically create the WCF service using the factories and classes available through .NET. The WCF service works fine for all code that already exists within the Service.
, :
public Objects.Helpers.IPathHelper GetPathHelper()
{
return new Helpers.PathHelper();
}
#endregion
unittests, , , PathHelper, /:
1 TestCase 'TenForce.Execution.API.ImplementationTest/HelperTests/CheckApplicationFolderPath' : System.ServiceModel.CommunicationException: . , , . wsrm: . .
: System.ServiceModel.Channels.ReliableRequestSessionChannel.SyncRequest.WaitForReply(- TimeSpan) System.ServiceModel.Channels.RequestChannel.Request( , - TimeSpan) System.ServiceModel.Dispatcher.RequestChannelBinder.Request( , - TimeSpan) System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object [] ins, Object [] outs, TimeSpan timeout) System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object [] ins, Object [] outs) System.ServiceModel.Channels.ServiceChannelProxy.InvokeService( IMethodCallMessageCall, ProxyOperationRuntime) System.ServiceModel.Channels.ServiceChannelProxy.Invoke( )
, [0]: System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData & msgData, Int32-) TenForce.Execution.API.Contracts.IAPI.GetPathHelper() TenForce.Execution.API.ServiceClient.ServiceAPI.GetPathHelper() c:\Users\arne.de.herdt\Documents\Trunk\Robinson\TenForce.Execution.API.ServiceClient\ServiceAPI.cs: 163 TenForce.Execution.API.ImplementationTest.HelperTests.CheckApplicationFolderPath() C:\Users\arne.de.herdt\Documents\Trunk\Robinson\TenForce.Execution.API.ImplementationTest\HelperTests.cs: 56 c:\Users\arne.de.herdt\Documents\Trunk\Robinson\TenForce.Execution.API.ServiceClient\ServiceAPI.cs 163
, , . , , , haywire, . , .