Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 基于MVP设计模式的WCF服务发布_C#_Wcf_Mvp - Fatal编程技术网

C# 基于MVP设计模式的WCF服务发布

C# 基于MVP设计模式的WCF服务发布,c#,wcf,mvp,C#,Wcf,Mvp,最近我已经学习了很多关于MVP设计模式的知识。我已经完成了整个解决方案,直到我开始使用表示层上的WCF服务为止。请在下面查找我遇到的问题的详细信息 我正在Windows窗体模型项目中使用服务引用。Windows窗体应用程序项目引用模型、视图和演示者项目 我遇到的例外情况是: Could not find default endpoint element that references contract 'ActionService.IActionService' in the Servi

最近我已经学习了很多关于MVP设计模式的知识。我已经完成了整个解决方案,直到我开始使用表示层上的WCF服务为止。请在下面查找我遇到的问题的详细信息

我正在Windows窗体模型项目中使用服务引用。Windows窗体应用程序项目引用模型、视图和演示者项目

我遇到的例外情况是:

    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.
“我的演示者”类的公共构造函数中出现异常,如下所示:

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; }
}
公共类演示者,其中T:IView
{
/// 
///获取并静态设置模型。
/// 
受保护的静态IModel模型{get;private set;}
/// 
///静态构造函数
/// 
静态演示者()
{
模型=新模型();
}
/// 
///构造函数。设置视图。
/// 
///景色。
公共演示者(T视图)
{
视图=视图;
}
/// 
///获取并设置视图。
/// 
公共T视图{get;私有集;}
}
以下是我的具体演示者类(AppConfigPresenter)的代码:

公共类AppConfigPresenter:Presenter
{
公共AppConfigPresenter(iApplicationConfiguration视图)
:底座(视图)
{
}
/// 
///显示窗体上的应用程序配置
/// 
/// 
/// 
公共无效显示(字节applicationId,字符串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");
    }
}
公共部分类FormMain:Form,iApplicationConfiguration视图
{
专用AppConfigPresenter\u AppConfigPresenter;
public FormMain()
{
初始化组件();
_appConfigPresenter=新的appConfigPresenter(此);
}
公共IList应用程序配置
{
设置
{ 
var应用程序配置=值;
BindApplicationConfiguration(应用程序配置);
}
}
私有应用程序配置(IList应用程序配置)
{
foreach(应用程序配置中的变量配置)
{
listBox1.Items.Add(config.ConfigKey);
}
}
私有无效按钮1\u单击(对象发送者,事件参数e)
{
_appConfigPresenter.Display(7,“xxxxxxx”);
}
}
这是我的web.config,位于我的托管层(即.svc所在的层)


以下是我的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);
    }
}
名称空间文件操作ServiceLayer.ServiceContracts
{
/// 
///IService是公共服务中运行模式的接口。
/// 
/// 
///应用程序外观模式。
/// 
[ServiceContract(SessionMode=SessionMode.Allowed)]
公共接口IActionService
{
[经营合同]
TokenResponse GetToken(TokenRequest请求);
[经营合同]
ApplicationConfiguration响应GetApplicationConfiguration(ApplicationConfiguration请求);
}
}
这是我的.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>


配置和服务合约中的合约名称必须相同(包括命名空间)。看起来您的配置不匹配:*FileManipulationServiceLayer.ServiceContracts.IActionService与“ActionService.IActionService”*

我添加了一些编辑,但仍然得到与以前相同的错误。我还可以给你们一些想法吗?App.config中的端点名称需要与合同名称相同吗?不,但我认为它必须与.svcOk中的名称相同。我已经修改了App.config,请看一看。它与新App.config正上方的.svc中的内容相匹配。仍然收到相同的错误。请将新配置中的名称更改为FileManipulationServiceLayer.ServiceImplementation.AppConfigService
    <?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>
<?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>