Question

I've been learning alot about the MVP design pattern as of late. I have gone through the entire solution up to the point where I'm starting to consume the WCF service on the presentation layer. Please find the details below for the issue I am running into.

I am using the service reference in the Windows Form Model project. The Windows Forms Application project references the Model, View, Presenter projects.

The exception i'm running into is:

    Could not find default endpoint element that references contract 'ActionService.IActionService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

The exception occurs in the public constructor of my Presenter class that looks like:

public class Presenter<T> where T : IView
{
    /// <summary>
    /// Gets and sets the model statically.
    /// </summary>
    protected static IModel Model { get; private set; }

    /// <summary>
    /// Static constructor
    /// </summary>
    static Presenter()
    {
        Model = new Model();
    }

    /// <summary>
    /// Constructor. Sets the view.
    /// </summary>
    /// <param name="view">The view.</param>
    public Presenter(T view)
    {
        View = view;
    }

    /// <summary>
    /// Gets and sets the view.
    /// </summary>
    public T View { get; private set; }
}

Here is the code for my concrete presenter class (AppConfigPresenter):

public class AppConfigPresenter : Presenter<IApplicationConfigurationView>
{
    public AppConfigPresenter(IApplicationConfigurationView view)
        : base(view)
    {

    }

    /// <summary>
    /// Displays the application configurations on the form
    /// </summary>
    /// <param name="applicationId"></param>
    /// <param name="machineName"></param>
    public void Display(byte applicationId, string machineName)
    {
        View.ApplicationConfigurations = Model.GetApplicationConfigurations(applicationId, machineName);
    }
}

In the windows forms application, here is the calling code:

public partial class FormMain : Form, IApplicationConfigurationView
{
    private AppConfigPresenter _appConfigPresenter;

    public FormMain()
    {
        InitializeComponent();
        _appConfigPresenter = new AppConfigPresenter(this);
    }

    public IList<ApplicationConfigurationModel> ApplicationConfigurations
    {
        set 
        { 
            var applicationConfigurations = value;

            BindApplicationConfigurations(applicationConfigurations);
        }
    }

    private void BindApplicationConfigurations(IList<ApplicationConfigurationModel> applicationConfigurations)
    {
        foreach(var config in applicationConfigurations)
        {
            listBox1.Items.Add(config.ConfigKey);
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
       _appConfigPresenter.Display(7, "xxxxxxx");
    }
}

Here's my web.config located in my hosting layer (which is the layer where the .svc resides.)

    <?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
      <services>
        <service behaviorConfiguration="AppConfigBehavior" name="FileManipulationServiceLayer.ServiceImplementation.AppConfigService">
          <endpoint address="" binding="wsHttpBinding" contract="FileManipulationServiceLayer.ServiceContracts.IActionService">
            <identity>
              <dns value="localhost"/>
            </identity>
          </endpoint>
          <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
      </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="AppConfigBehavior">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
</configuration>

Here is my app.config that is in my Windows Forms Model Project:

    <?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IActionService" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:51516/ActionService.svc"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IActionService"
                contract="ActionService.IActionService"
                name="WSHttpBinding_IActionService">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

EDIT:

Here's is my service contact:

namespace FileManipulationServiceLayer.ServiceContracts
{
    /// <summary>
    /// IService is the interface for Patterns in Action public services.
    /// </summary>
    /// <remarks>
    /// Application Facade Pattern.
    /// </remarks>
    [ServiceContract(SessionMode = SessionMode.Allowed)]
    public interface IActionService
    {
        [OperationContract]
        TokenResponse GetToken(TokenRequest request);

        [OperationContract]
        ApplicationConfigurationResponse GetApplicationConfigurations(ApplicationConfigurationRequest request);
    }
}

Here is my .svc file:

<%@ ServiceHost Language="C#" Debug="true" Service="FileManipulationServiceLayer.ServiceImplementation.AppConfigService" %>

My new App.config file:

    <?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IActionService" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:51516/ActionService.svc"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IActionService"
                contract="FileManipulationServiceLayer.ServiceImplementation.AppConfigService" name="WSHttpBinding_IActionService">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

I am still getting the same error as previously mentioned.

NEW EDIT:

Whenever I update the service reference, it's adding more to the app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IActionService" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" />
                    </security>
                </binding>
                <binding name="WSHttpBinding_IActionService1" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:51516/ActionService.svc"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IActionService"
                contract="FileManipulationServiceLayer.ServiceImplementation.AppConfigService"
                name="WSHttpBinding_IActionService">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
            <endpoint address="http://localhost:51516/ActionService.svc"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IActionService1"
                contract="ActionService.IActionService" name="WSHttpBinding_IActionService1">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>
Was it helpful?

Solution

The contract names must be identical (including namespace) in the configs and service contract. It looks you've got a mismatch: *FileManipulationServiceLayer.ServiceContracts.IActionService vs. 'ActionService.IActionService'*

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top