0

私は最近、MVP デザイン パターンについて多くのことを学んでいます。プレゼンテーション レイヤーで WCF サービスを使用し始めるところまで、ソリューション全体を確認しました。私が直面している問題については、以下の詳細をご覧ください。

Windows フォーム モデル プロジェクトでサービス参照を使用しています。Windows フォーム アプリケーション プロジェクトは、Model、View、Presenter プロジェクトを参照します。

私が実行している例外は次のとおりです。

    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.

次のような Presenter クラスのパブリック コンストラクターで例外が発生します。

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; }
}

具体的なプレゼンター クラス (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);
    }
}

Windows フォーム アプリケーションの呼び出しコードは次のとおりです。

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");
    }
}

これは、私のホスティング レイヤー (.svc が存在するレイヤー) にある web.config です。

    <?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>

私の Windows フォーム モデル プロジェクトにある私の 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>
            </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>

編集:

これが私のサービス連絡先です:

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);
    }
}

ここに私の.svcファイルがあります:

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

私の新しい 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>
            </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>

前述と同じエラーが引き続き発生します。

新しい編集:

サービス参照を更新するたびに、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>
4

1 に答える 1

0

コントラクト名は、構成とサービス コントラクトで (名前空間を含めて) 同一である必要があります。不一致があるようです: *FileManipulationServiceLayer.ServiceContracts.IActionService'ActionService.IActionService'*

于 2013-06-26T15:59:10.493 に答える