صندوق رأس المال العامل:لا يمكن العثور على أداة التحقق المخصصة الخاصة بي المحددة في web.config - customUserNamePasswordValidatorType - - لا يمكن تحميل الملف أو التجميع ... - مساعدة؟

StackOverflow https://stackoverflow.com/questions/1805702

  •  05-07-2019
  •  | 
  •  

سؤال

لقد قمت بشكل أساسي بإعداد كل شيء وتشغيله باستخدام wsHttpBindings وخدمة WCF الخاصة بي باستخدام المصادقة المخصصة عبر HTTPS.

المشكلة التي أواجهها تتعلق بـ customUserNamePasswordValidatorType:

  <serviceCredentials>
    <!-- Use our own custom validation -->
    <userNameAuthentication userNamePasswordValidationMode="Custom"
                            customUserNamePasswordValidatorType="CustomValidator.CustomUserNameValidator, CustomValidator"/>
  </serviceCredentials>

تم العثور على الاتجاهات التالية هنا لقد قمت بإنشاء فصلي المخصص أيضًا:

namespace CustomValidator
{
    public class CustomUserNameValidator : UserNamePasswordValidator
    {
        public override void Validate(string userName, string password)
        {
            if (null == userName || null == password)
            {
                throw new ArgumentNullException();
            }


            if (!AuthenticateUser(userName, password))
                throw new SecurityTokenValidationException("Invalid Credentials");

الخطأ هو "تعذر تحميل الملف أو التجميع "CustomValidator" أو أحد تبعياته.لا يمكن للنظام العثور على الملف المحدد."، ويشير إلى نهاية customUserNamePasswordValidatorType - "...، CustomValidator".

لم أكن أعتقد أن وجود أداة التحقق المخصصة الخاصة بي في مساحة الاسم والفصل الخاصة بها يمثل مشكلة، لكن لا يمكنني رؤية ما يجب فعله لإنجاح هذا العمل.

لقد حاولت مع/بدون مساحة الاسم في البداية، والتبديل، وما إلى ذلك - لا شيء.

على أمل أن يتمكن زوج آخر من العيون من اكتشاف ذلك.

شكرًا.

EDIT system.serviceModel

  <system.serviceModel>
    <bindings>

      <!-- wsHttpBinding -->
      <wsHttpBinding>
        <binding name="wsHttpEndpointBinding">
          <security mode="TransportWithMessageCredential">
            <transport clientCredentialType="None" />
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsHttpBinding>

      <!-- webHttpBinding -->
      <webHttpBinding>
        <binding name="wsHttps" >
          <security mode="Transport"/>
        </binding>
      </webHttpBinding>

      <!-- Basic binding -->
      <basicHttpBinding>
        <binding name="TransportSecurity">
          <security mode="Transport">
            <message clientCredentialType="UserName"/>
            <!-- transport clientCredentialType="None"/-->
          </security>
        </binding>
      </basicHttpBinding>

      <!-- customBinding>
        <binding name="WebHttpBinding_IService">
          textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
              messageVersion="Soap12" writeEncoding="utf-8">
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          </textMessageEncoding>
          <httpsTransport manualAddressing="false"/>
        </binding>
      </customBinding -->
      <!-- Another custom binding -->
      <customBinding>
        <binding name="CustomMapper">
          <webMessageEncoding  webContentTypeMapperType=
                 "IndexingService.CustomContentTypeMapper, IndexingService" />
          <httpTransport manualAddressing="true" />
        </binding>
      </customBinding>
    </bindings>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" />
    <services>
      <service behaviorConfiguration="ServiceBehavior" name="Service">




        <!-- Service Endpoints -->
        <!-- since we're hosting in IIS, baseAddress is not required 
        <host>
          <baseAddresses>
            <add baseAddress="https://mysslserver.com/Service.svc"/>
          </baseAddresses>
        </host>
        -->
        <endpoint address="https://mysslserver.com/Service.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="wsHttpEndpointBinding" 
                  contract="IService"
                  name="wsHttpEndpoint">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <!--identity>
            <dns value="https://mysslserver.com"/>
          </identity-->
        </endpoint>

        <!-- endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/ -->
      </service>
    </services>
    <behaviors>

      <endpointBehaviors>
        <behavior name="webBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>

      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <!-- Setup Security/Error Auditing -->
          <serviceSecurityAudit auditLogLocation="Application"
                suppressAuditFailure="false"
                serviceAuthorizationAuditLevel="Failure"
                messageAuthenticationAuditLevel="Failure" />

          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"
                           httpsGetUrl="https://mysslserver.com/Service.svc"/>
          <serviceDebug includeExceptionDetailInFaults="false" />
          <serviceCredentials>
            <!-- Use our own custom validation -->
            <userNameAuthentication userNamePasswordValidationMode="Custom"
                                    customUserNamePasswordValidatorType="CustomValidator.CustomUserNameValidator, CustomValidator"/>
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>

      <!-- serviceBehaviors>
        <behavior name="ServiceBehavior">
        <serviceMetadata httpsGetEnabled="true" 
                           httpsGetUrl="https://mysslserver.com/Service.svc" />
          To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information 
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior-->
    </behaviors>
  </system.serviceModel>
هل كانت مفيدة؟

المحلول

قررت أن أعطيها طعنة أخرى، ولم يعجبني وجود أداة التحقق المخصصة الخاصة بي في lib آخر.

لذلك قمت بإنشاء فئة جديدة في App_Code، وذهبت إليها...

وفيما يلي ما تم إصلاحه بالفعل،

="CustomValidator.CustomUserNameValidator, App_Code"

نصائح أخرى

عند الرجوع إلى المدقق المخصص بالقيم

="CustomValidator.CustomUserNameValidator, CustomValidator"

The first value is the type name and the second is the name of the assembly in which to find the type. So I would suggest that in your first instance your service is actually in some other assembly such as MyService In that case you really needed your config file to say

="CustomValidator.CustomUserNameValidator, MyService"

I suspect that when you have created your new class library for your validator, you have called your project CustomValidator (which will output an assembly called CustomValidator.dll), and hence now your config will work (i.e. it has nothing to do with being in a separate class library - it just happens that the naming of your assembly reference in the web.config is now valid)

يبدو الأمر غريبًا بعض الشيء، ولكن الحل كان إنشاء مكتبة فئة منفصلة والإشارة إلى مكتبة الارتباط الحيوي (DLL) الخاصة بها في خدمة WCF الخاصة بي.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.ServiceModel;

/// <summary>
/// Summary description for CustomUsernamePasswordValidator
/// </summary>
namespace CustomValidator
{
    public class CustomUserNameValidator : UserNamePasswordValidator
    {
        public override void Validate(string userName, string password)
        {
            if (null == userName || null == password)
            {
                throw new ArgumentNullException();
            }


            if (!AuthenticateUser(userName, password))
                throw new SecurityTokenValidationException("Invalid Credentials");
            else
            {
                // do nothing - they're good
            }
        }

        public bool AuthenticateUser(string userName, string password)
        {
            if (userName != "userbill" || password != "passwordbill")
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}

ثم أضفت إشارة إلى System.IdentityModel وSystem.ServiceModel.

تم الآن تغيير قسم "serviceCredentials" لخدمة WCF إلى ما يلي:

<serviceCredentials>
    <!-- Use our own custom validation -->
    <userNameAuthentication userNamePasswordValidationMode="Custom"
                            customUserNamePasswordValidatorType="CustomValidator.CustomUserNameValidator, CustomValidator"/>
</serviceCredentials>

نأمل أن يساعد شخص ما.

لقد حاولت ذلك باستخدام بيانات اعتماد غير صالحة، وكنت أتوقع رؤية رسالة "بيانات اعتماد غير صالحة".وبدلاً من ذلك تظهر لي الرسالة "تعذر التحقق من صحة رمز أمان واحد على الأقل في الرسالة."

بخلاف ذلك، تم تشغيل هذا الشيء أخيرًا!

مجرد قراءة هذا لأنه كان مفيدًا بالنسبة لنقطة الاتصال (POC) وكان علي أن أبدأ بسرعة.للإستجابة ل الهيكس أعلاه...يجب أن يعمل هذا على ضمان إعادة الخطأ الوصفي المخصص إلى العميل:

using System.ServiceModel
...    
throw new FaultException("Invalid Credentials - Custom Error");
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top