WCF CommunicationException on data return

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
{
/// <summary>
/// <para>This interface defines the functionality available in the PathHelper for the API.</para>
/// </summary>
public interface IPathHelper
{
    string ApplicationFolder { get; }   // The HomeDataFolder for the application
    string CompanyHomeFolder { get; }   // The HomeDataFolder for the company.
    string CustomFolder { get; }        // The custom folder for professional services.
    string WikiFolder { get; }          // The WIKI folder to store pages.
    string AddinsFolder { get; }        // The AddinFolder to access the addins.
}
}

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
{
/// <summary>
/// <para>This class provides a direct implementation of the IPathHelper for the API implementation
/// and manages all the paths inside the DataHomeFolder structure for the TenForce application.</para>
/// </summary>
[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

    /// <summary>
    /// <para>Creates a new instance of the PathHelper class</para>
    /// </summary>
    public PathHelper()
    {
        _mParameterBul = new ParameterBUL();
    }

    #endregion

    #region IPathHelper Members

    /// <summary>
    /// <para>Returns the absolute path to the DataHomeFolder of the TenForce Application.</para>
    /// </summary>
    [DataMember]
    public string ApplicationFolder
    {
        get
        {
            return CreatePath(_mParameterBul.GetParameterValue(DataHomeFolderId));
        }
    }

    /// <summary>
    /// <para>Returns the absolute path to the Company DataHomeFolder.</para>
    /// </summary>
    [DataMember]
    public string CompanyHomeFolder
    {
        get
        {
            return CreatePath(Path.Combine(ApplicationFolder, _mParameterBul.GetParameterValue(CompanyNameId)));
        }
    }

    /// <summary>
    /// <para>Returns the absolute path to the Company custom folder.</para>
    /// </summary>
    [DataMember]
    public string CustomFolder
    {
        get
        {
            return CreatePath(Path.Combine(CompanyHomeFolder, @"custom"));
        }
    }

    /// <summary>
    /// <para>Returns the absolute path to the Company wiki folder.</para>
    /// </summary>
    [DataMember]
    public string WikiFolder
    {
        get
        {
            return CreatePath(Path.Combine(CompanyHomeFolder, @"wiki"));
        }
    }

    /// <summary>
    /// <para>Returns the absolute path to the Company addins folder.</para>
    /// </summary>
    [DataMember]
    public string AddinsFolder
    {
        get
        {
            return CreatePath(Path.Combine(CompanyHomeFolder, @"addins"));
        }
    }

    #endregion

    #region Private Members

    /// <summary>
    /// <para>Checks if the specified path exists, and creates the path 
    /// if the system cannot find it.</para>
    /// </summary>
    /// <param name="path">The path to verify.</param>
    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.

, :

    /// <summary>
    /// <para>Returns the PathHelper to construct the various paths for API Scripts.</para>
    /// </summary>
    /// <returns>An instance of the PathHelper.</returns>
    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, . , .

+3
2

, API WCF.

, WCF. , , .

0

, , , .

, ( ). DataMember accesor, . MSDN:

, DataMemberAttribute, , ; .

DataMember

, , m_ParameterBul, , DataMember DataMember readonly .

, m_ParameterBul , , . .

, !

/// <summary>
/// <para>This class provides a direct implementation of the IPathHelper for the API implementation
/// and manages all the paths inside the DataHomeFolder structure for the TenForce application.</para>
/// </summary>
[DataContract]
public class PathHelper : Objects.Helpers.IPathHelper
{
    #region Private Fields
    [DataMember]
    private readonly ParameterBUL _mParameterBul;
    private const Parameter.ParameterId DataHomeFolderId = Parameter.ParameterId.DataHomeFolder;
    private const Parameter.ParameterId CompanyNameId = Parameter.ParameterId.CompanyName;

    #endregion

    #region Constructor

    /// <summary>
    /// <para>Creates a new instance of the PathHelper class</para>
    /// </summary>
    public PathHelper()
    {
        _mParameterBul = new ParameterBUL();
    }

    #endregion

    #region IPathHelper Members

    /// <summary>
    /// <para>Returns the absolute path to the DataHomeFolder of the TenForce Application.</para>
    /// </summary>   
    public string ApplicationFolder
    {
        get
        {
            return CreatePath(_mParameterBul.GetParameterValue(DataHomeFolderId));
        }
    }

    /// <summary>
    /// <para>Returns the absolute path to the Company DataHomeFolder.</para>
    /// </summary>   
    public string CompanyHomeFolder
    {
        get
        {
            return CreatePath(Path.Combine(ApplicationFolder, _mParameterBul.GetParameterValue(CompanyNameId)));
        }
    }

    /// <summary>
    /// <para>Returns the absolute path to the Company custom folder.</para>
    /// </summary>
    public string CustomFolder
    {
        get
        {
            return CreatePath(Path.Combine(CompanyHomeFolder, @"custom"));
        }
    }

    /// <summary>
    /// <para>Returns the absolute path to the Company wiki folder.</para>
    /// </summary>
    public string WikiFolder
    {
        get
        {
            return CreatePath(Path.Combine(CompanyHomeFolder, @"wiki"));
        }
    }

    /// <summary>
    /// <para>Returns the absolute path to the Company addins folder.</para>
    /// </summary>    
    public string AddinsFolder
    {
        get
        {
            return CreatePath(Path.Combine(CompanyHomeFolder, @"addins"));
        }
    }

    #endregion

    #region Private Members

    /// <summary>
    /// <para>Checks if the specified path exists, and creates the path 
    /// if the system cannot find it.</para>
    /// </summary>
    /// <param name="path">The path to verify.</param>
    private static string CreatePath(string path)
    {
        if (!Directory.Exists(path))
            Directory.CreateDirectory(path);
        return path;
    }

    #endregion
}
+1

All Articles