使用SSL和自定义身份验证的WCF服务

时间:2016-04-15 10:16:49

标签: vb.net wcf ssl

所以我正在尝试创建一个使用SSL和自定义身份验证器的WCF服务。

这是服务器配置:

Imports System.IdentityModel.Selectors

Public Class Verification
    Inherits UserNamePasswordValidator

    Public Overrides Sub Validate(userName As String, password As String)

        If Not (username = "Admin" AndAlso password = "Fake Password") Then
            Throw New Exception("Wrong Username Password combination.")
        End If

    End Sub

End Class

这是我的验证类:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.diagnostics>
        <sources>
            <source name="System.ServiceModel.MessageLogging" switchValue="Warning,ActivityTracing">
                <listeners>
                    <add type="System.Diagnostics.DefaultTraceListener" name="Default">
                        <filter type="" />
                    </add>
                    <add name="ServiceModelMessageLoggingListener">
                        <filter type="" />
                    </add>
                </listeners>
            </source>
        </sources>
        <sharedListeners>
            <add initializeData="c:\users\connor smith\documents\visual studio 2015\projects\wcfserviceconsumer\wcfserviceconsumer\app_messages.svclog"
                type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
                <filter type="" />
            </add>
        </sharedListeners>
        <trace autoflush="true" />
    </system.diagnostics>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
    <system.serviceModel>
        <diagnostics>
            <messageLogging logEntireMessage="true" logMalformedMessages="true"
                logMessagesAtTransportLevel="true" />
        </diagnostics>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IService1">
                    <security mode="TransportWithMessageCredential">
                        <transport clientCredentialType="None" />
                        <message clientCredentialType="UserName" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://mysite.co.uk/WCFService/Service1.svc"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
                contract="AService.IService1" name="WSHttpBinding_IService1" />
        </client>
    </system.serviceModel>
</configuration>

App Config:

Class Base {
  void fun() {
    System.out.println("fun");
  }
}

Class Sub extends Base{
  void fun () {
    System.out.println("In fun");
  }

  void display () {
    System.out.println ("Display");
  }
}

Base obj = new Sub ();
obj.fun();
obj.display();

我在测试应用程序中使用它,然后我将用户名和密码设置为管理员和假密码,然后我去使用该服务并获得以下错误: Error

编辑:更多错误信息:

'mscorlib.dll'中发生了'System.ServiceModel.ProtocolException'类型的未处理异常

我错过了什么吗?

0 个答案:

没有答案