Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.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# 具有自定义用户名/密码验证的基于WCF会话的服务:配置问题_C#_Wcf_Custom Authentication - Fatal编程技术网

C# 具有自定义用户名/密码验证的基于WCF会话的服务:配置问题

C# 具有自定义用户名/密码验证的基于WCF会话的服务:配置问题,c#,wcf,custom-authentication,C#,Wcf,Custom Authentication,我已经在stackoverflow上搜索了很多已经发布的答案,但是到目前为止,没有一个解决方案没有解决我的问题。这是第二天的研究和故障排除没有结果,所以我要向其他人寻求帮助。我正在开发一个WPF数据库应用程序,我想在WPF应用程序和数据库之间添加一个中间层WCF WCF服务有两个服务合约,两个合约都需要启用自定义用户名/密码身份验证会话。第一个服务合同IAppUserService将为本地用户运行的WPF应用程序提供服务,第二个服务合同将为客户IAppClientService访问的网站提供服务

我已经在stackoverflow上搜索了很多已经发布的答案,但是到目前为止,没有一个解决方案没有解决我的问题。这是第二天的研究和故障排除没有结果,所以我要向其他人寻求帮助。我正在开发一个WPF数据库应用程序,我想在WPF应用程序和数据库之间添加一个中间层WCF

WCF服务有两个服务合约,两个合约都需要启用自定义用户名/密码身份验证会话。第一个服务合同IAppUserService将为本地用户运行的WPF应用程序提供服务,第二个服务合同将为客户IAppClientService访问的网站提供服务

我包含了以下源代码:

DCMAppService.svc.cs

服务的接口文件包含以下内容:

<?xml version="1.0"?>
<configuration>
    <appSettings/>
    <connectionStrings>
        <add name="DCMConnectionString" connectionString="Server=127.0.0.1;Database=xxxxxx;Uid=xxxxxx;Pwd=xxxxxx;" providerName="System.Data.EntityClient"/>
    </connectionStrings>
    <system.web>
        <compilation debug="true" targetFramework="4.0">
        </compilation>
        <!--
        The <authentication> section enables configuration 
        of the security authentication mode used by 
        ASP.NET to identify an incoming user. 
    -->
        <authentication mode="Windows"/>
        <!--
        The <customErrors> section enables configuration 
        of what to do if/when an unhandled error occurs 
        during the execution of a request. Specifically, 
        it enables developers to configure html error pages 
        to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
         <error statusCode="403" redirect="NoAccess.htm" />
         <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
      -->
        <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
    </system.web>
    <system.serviceModel>
        <protocolMapping>
            <remove scheme="http" />
            <add scheme="http" binding="wsHttpBinding" />
        </protocolMapping>
        <bindings>
            <wsHttpBinding>
                <binding name="DCMAppBindingWSConfig" receiveTimeout="03:00:00"
                 sendTimeout="03:00:00">
                    <reliableSession inactivityTimeout="01:00:00" enabled="true" />
                    <security mode="Message">
                        <message clientCredentialType="UserName" />
                    </security>
                </binding>
            </wsHttpBinding>
            <mexHttpBinding>
                <binding name="DCMAppBindingMexConfig" receiveTimeout="00:10:00"
                 sendTimeout="00:10:00" />
            </mexHttpBinding>
        </bindings>
        <services>
            <service behaviorConfiguration="DCMAppService.AppServiceBehavior"
             name="DCMAppService.AppUserService">
                <endpoint address="" binding="wsHttpBinding" name="wsBinding"
                 contract="DCMAppService.IAppUserService">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="DCMAppBindingMexConfig"
                 name="mexBinding" contract="IMetadataExchange" />
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="DCMAppService.AppServiceBehavior">
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true" />
                    <serviceCredentials>
                        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="DCMAppService.CustomUserNameValidator, DCMAppService" />
                    </serviceCredentials>
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
</configuration>
IDCMAppService.cs

请注意,它包含两个不同的服务合同,WCF必须为一个用户和另一个客户端提供服务

Web.config文件包含以下内容:

<?xml version="1.0"?>
<configuration>
    <appSettings/>
    <connectionStrings>
        <add name="DCMConnectionString" connectionString="Server=127.0.0.1;Database=xxxxxx;Uid=xxxxxx;Pwd=xxxxxx;" providerName="System.Data.EntityClient"/>
    </connectionStrings>
    <system.web>
        <compilation debug="true" targetFramework="4.0">
        </compilation>
        <!--
        The <authentication> section enables configuration 
        of the security authentication mode used by 
        ASP.NET to identify an incoming user. 
    -->
        <authentication mode="Windows"/>
        <!--
        The <customErrors> section enables configuration 
        of what to do if/when an unhandled error occurs 
        during the execution of a request. Specifically, 
        it enables developers to configure html error pages 
        to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
         <error statusCode="403" redirect="NoAccess.htm" />
         <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
      -->
        <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
    </system.web>
    <system.serviceModel>
        <protocolMapping>
            <remove scheme="http" />
            <add scheme="http" binding="wsHttpBinding" />
        </protocolMapping>
        <bindings>
            <wsHttpBinding>
                <binding name="DCMAppBindingWSConfig" receiveTimeout="03:00:00"
                 sendTimeout="03:00:00">
                    <reliableSession inactivityTimeout="01:00:00" enabled="true" />
                    <security mode="Message">
                        <message clientCredentialType="UserName" />
                    </security>
                </binding>
            </wsHttpBinding>
            <mexHttpBinding>
                <binding name="DCMAppBindingMexConfig" receiveTimeout="00:10:00"
                 sendTimeout="00:10:00" />
            </mexHttpBinding>
        </bindings>
        <services>
            <service behaviorConfiguration="DCMAppService.AppServiceBehavior"
             name="DCMAppService.AppUserService">
                <endpoint address="" binding="wsHttpBinding" name="wsBinding"
                 contract="DCMAppService.IAppUserService">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="DCMAppBindingMexConfig"
                 name="mexBinding" contract="IMetadataExchange" />
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="DCMAppService.AppServiceBehavior">
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true" />
                    <serviceCredentials>
                        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="DCMAppService.CustomUserNameValidator, DCMAppService" />
                    </serviceCredentials>
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
</configuration>
我得到的回应是带有经典消息的错误页面:

此服务的元数据发布当前已禁用

这是相当恼人的,因为我找不到任何办法来解决它

任何帮助都将不胜感激

<?xml version="1.0"?>
<configuration>
    <appSettings/>
    <connectionStrings>
        <add name="DCMConnectionString" connectionString="Server=127.0.0.1;Database=xxxxxx;Uid=xxxxxx;Pwd=xxxxxx;" providerName="System.Data.EntityClient"/>
    </connectionStrings>
    <system.web>
        <compilation debug="true" targetFramework="4.0">
        </compilation>
        <!--
        The <authentication> section enables configuration 
        of the security authentication mode used by 
        ASP.NET to identify an incoming user. 
    -->
        <authentication mode="Windows"/>
        <!--
        The <customErrors> section enables configuration 
        of what to do if/when an unhandled error occurs 
        during the execution of a request. Specifically, 
        it enables developers to configure html error pages 
        to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
         <error statusCode="403" redirect="NoAccess.htm" />
         <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
      -->
        <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
    </system.web>
    <system.serviceModel>
        <protocolMapping>
            <remove scheme="http" />
            <add scheme="http" binding="wsHttpBinding" />
        </protocolMapping>
        <bindings>
            <wsHttpBinding>
                <binding name="DCMAppBindingWSConfig" receiveTimeout="03:00:00"
                 sendTimeout="03:00:00">
                    <reliableSession inactivityTimeout="01:00:00" enabled="true" />
                    <security mode="Message">
                        <message clientCredentialType="UserName" />
                    </security>
                </binding>
            </wsHttpBinding>
            <mexHttpBinding>
                <binding name="DCMAppBindingMexConfig" receiveTimeout="00:10:00"
                 sendTimeout="00:10:00" />
            </mexHttpBinding>
        </bindings>
        <services>
            <service behaviorConfiguration="DCMAppService.AppServiceBehavior"
             name="DCMAppService.AppUserService">
                <endpoint address="" binding="wsHttpBinding" name="wsBinding"
                 contract="DCMAppService.IAppUserService">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="DCMAppBindingMexConfig"
                 name="mexBinding" contract="IMetadataExchange" />
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="DCMAppService.AppServiceBehavior">
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true" />
                    <serviceCredentials>
                        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="DCMAppService.CustomUserNameValidator, DCMAppService" />
                    </serviceCredentials>
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
</configuration>