Vb.net Can';t在Visual Studio 2015中运行WCF服务应用程序
我正在尝试创建我的第一个WCF服务应用程序,但无法从Visual Studio 2015运行它 这是我单击“运行”时出现的错误 我在学习一个教程,我想他们跳过了几个步骤,但下面是我添加到web.config的内容Vb.net Can';t在Visual Studio 2015中运行WCF服务应用程序,vb.net,wcf,visual-studio-2015,Vb.net,Wcf,Visual Studio 2015,我正在尝试创建我的第一个WCF服务应用程序,但无法从Visual Studio 2015运行它 这是我单击“运行”时出现的错误 我在学习一个教程,我想他们跳过了几个步骤,但下面是我添加到web.config的内容 <services> <service name="OnPatrolRest.Service1"> <endpoint address="http://localhost:51964/service1" binding="
<services>
<service name="OnPatrolRest.Service1">
<endpoint address="http://localhost:51964/service1"
binding="webHttpBinding"
contract="OnPatrolRest.IService1"/>
</service>
</services>
这是我添加的唯一函数。我错过了什么。我对这个很陌生。我看到的每一篇文章都是几年前的,在VS 2015中不起作用
非常感谢您的帮助 在控制台应用程序中,这对我很有效。不需要
Web.config
或App.config
主模块
Module Main
Sub Main()
With New Manager(GetType(Service), "SomeService", 8080)
Environment.ExitCode = .StartService
End With
End Sub
End Module
<ServiceContract>
Public Interface IService
<OperationContract> Function GetFilteredResult(Workstations As List(Of String), ProcessName As String) As Result
<OperationContract> Function GetResult(Workstations As List(Of String)) As Result
End Interface
服务经理
Friend Class Manager
Implements ServiceControl
Public Sub New(ServiceType As Type, ServiceName as String, WcfPort As Integer)
Me.ServiceType = ServiceType
Me.ServiceName = ServiceName
Me.WcfPort = WcfPort
End Sub
Public Sub StartService
Try
Me.OpenServiceHost()
Catch ex As Exception
End Try
End Sub
Public Sub StopService
Try
Me.CloseServiceHost()
Catch ex As Exception
End Try
End Sub
Public Sub OpenServiceHost()
Me.ServiceHost.Open()
End Sub
Public Sub CloseServiceHost()
If Me.ServiceHost.IsNotNothing Then
If Me.ServiceHost.State <> CommunicationState.Closed Then
Me.ServiceHost.Close()
End If
End If
End Sub
Private ReadOnly Property ServiceHost As ServiceHost
Get
If _ServiceHost Is Nothing Then
_ServiceHost = New ServiceHost(Me.ServiceType, Me.ListenerAddress)
_ServiceHost.AddDefaultEndpoints()
End If
Return _ServiceHost
End Get
End Property
Private _ServiceHost As ServiceHost
Private ReadOnly Property ListenerAddress As Uri
Get
Return New Uri($"http://{Environment.MachineName}:{Me.WcfPort}/{Me.ServiceName}")
End Get
End Property
Private Property ServiceName As String
Private Property WcfPort As Integer
End Class
我通常把这些和TopShelf搭配;这种组合提供了一个很好的自我托管的WCF服务,包装在Windows服务中
Friend Class Manager
Implements ServiceControl
Public Sub New(ServiceType As Type, ServiceName as String, WcfPort As Integer)
Me.ServiceType = ServiceType
Me.ServiceName = ServiceName
Me.WcfPort = WcfPort
End Sub
Public Sub StartService
Try
Me.OpenServiceHost()
Catch ex As Exception
End Try
End Sub
Public Sub StopService
Try
Me.CloseServiceHost()
Catch ex As Exception
End Try
End Sub
Public Sub OpenServiceHost()
Me.ServiceHost.Open()
End Sub
Public Sub CloseServiceHost()
If Me.ServiceHost.IsNotNothing Then
If Me.ServiceHost.State <> CommunicationState.Closed Then
Me.ServiceHost.Close()
End If
End If
End Sub
Private ReadOnly Property ServiceHost As ServiceHost
Get
If _ServiceHost Is Nothing Then
_ServiceHost = New ServiceHost(Me.ServiceType, Me.ListenerAddress)
_ServiceHost.AddDefaultEndpoints()
End If
Return _ServiceHost
End Get
End Property
Private _ServiceHost As ServiceHost
Private ReadOnly Property ListenerAddress As Uri
Get
Return New Uri($"http://{Environment.MachineName}:{Me.WcfPort}/{Me.ServiceName}")
End Get
End Property
Private Property ServiceName As String
Private Property WcfPort As Integer
End Class
<ServiceContract>
Public Interface IService
<OperationContract> Function GetFilteredResult(Workstations As List(Of String), ProcessName As String) As Result
<OperationContract> Function GetResult(Workstations As List(Of String)) As Result
End Interface
Public Class Service
Implements IService
Public Function GetFilteredResult(Workstations As List(Of String), ProcessName As String) As Result Implements IService.GetFilteredResult
'
' Code goes here
'
End Function
Public Function GetResult(Workstations As List(Of String)) As Result Implements IService.GetResult
'
' Code goes here
'
End Function
End Class