无法将用户控件添加到现有WCF服务

时间:2014-05-23 10:17:19

标签: .net vb.net wcf

我开发了一个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

OperationContracts:

<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 导入Tokes,但我还没有找到如何导入选择器

而且,一旦这个条款可以正确地添加到项目中,我该如何继续在WCF上引入用户控件?我应该在web.config文件中执行哪些修改?。

提前致谢!

1 个答案:

答案 0 :(得分:0)

确保您已为所有类别和方法定义了合适的合同,

<OperationContract()>

http://msdn.microsoft.com/en-us/library/bb386386.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

这是VB.NET中WCF的最佳方法,希望这对您有帮助,

http://www.aspnettutorials.com/tutorials/advanced/introduction-to-wcf-vb/