【发布时间】:2014-05-23 10:17:19
【问题描述】:
我开发了一个 WCF 服务,效果很好。但是,此服务不提供任何用户控制,我现在正在尝试添加此功能。
你可以找到 WCF 类:
Public Class WCF_ServicioWeb
Implements IWCF_ServicioWeb
Public Sub New()
End Sub
Public Function HelloWorld() As String Implements IWCF_ServicioWeb.HelloWorld
Return My.Resources.CONST_HELLO_WORLD
End Function
Public Function EnviarFichero(ByVal composite As CompositeType) As Integer Implements IWCF_ServicioWeb.EnviarFichero
'Do some ooperations.
Return 0
End Function
End Class
操作合同:
<ServiceContract()>
Public Interface IWCF_ServicioWeb
<OperationContract()>
Function HelloWorld() As String
<OperationContract()>
Function EnviarFichero(ByVal composite As CompositeType) As Integer
End Interface
<DataContract()>
Public Class CompositeType
<DataMember()>
Public Property nombreFichero() As String
<DataMember()>
Public Property lugarAdq() As String
<DataMember()>
Public Property sCadenaDeTexto() As String
End Class
现在您可以使用 web.config 文件了:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="WCF_ServicioWeb.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
<readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
在网上看了一下,发现为了引入用户控件,类:
Imports System
Imports System.ServiceModel
Imports System.IdentityModel.Tokens
Imports System.IdentityModel.Selectors
Imports System.Security.Principal
Public Class CustomUserNameValidator
Inherits UserNamePasswordValidator
Public Overrides Sub Validate(ByVal userName As String, ByVal password As String)
If ((userName = "user") And (password = "password")) Then
'passed
Else
Throw New FaultException("Invalid credentials")
End If
End Sub
End Class
但是,我收到一个错误,因为类 UserNamePasswordValidator、lib Imports System.IdentityModel.Selectors 和 lib Imports System.IdentityModel。找不到令牌。我正在使用 vb.net (VS2010) 和 NET Framework 4.0。 任何人都知道为什么会发生这种情况? 我检查了可以从 lib System.ServiceModel.Security.Tokens 而不是 System.IdentityModel.Tokens 导入令牌,但我还没有找到如何导入选择器。
而且,一旦这个类可以正确地添加到项目中,我必须如何继续在 WCF 上引入用户控件?为此,我应该对 web.config 文件进行哪些修改?
提前致谢!
【问题讨论】: