【发布时间】:2016-02-17 03:30:02
【问题描述】:
我有一个托管在 Windows 服务中的 WCF 服务。我想要做的是调用位于客户端 PC 和 WS 上的 Windows 服务 (WS) 来调用同一客户端计算机上的客户端 DLL。 我已经在每台客户端 PC 和服务器上安装了 WS。当导航到服务器上的 ASP.NET 页面并调用该方法时,它工作正常,但是客户端 PC 不是从本地 WS 调用它们的 DLL,而是调用在服务器上调用的 WS - 这不是期望的行为。此环境将安装在 LAN 上。
我有一个示例方法是获取 PC 名称,这错误地作为回报我得到了服务器的名称。
这是我的 app.config 文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<!-- This section is optional with the new configuration model
introduced in .NET Framework 4. -->
<service name="Service.CalculatorService" behaviorConfiguration="CalculatorServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/ServiceModelSamples/service"/>
</baseAddresses>
</host>
<!-- this endpoint is exposed at the base address provided by host: http://localhost:8000/ServiceModelSamples/service -->
<endpoint address=""
binding="wsHttpBinding"
contract="Service.ICalculator" />
<!-- the mex endpoint is exposed at http://localhost:8000/ServiceModelSamples/service/mex -->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
我的服务等级:
Public Interface ICalculator
<OperationContract()> _
Function GetPCname() As String
Sub OpenPort()
<OperationContract()> _
End Interface
Public Class CalculatorService
Implements ICalculator
<DllImport("C:\App_32bit\test.dll", CharSet:=CharSet.Ansi)> _
Private Shared Function DrvOpen(ByVal cha As String, ByRef ope As T_open, ByRef out As T_open_out) As Short
End Function
Public Function GetPCname() As String Implements ICalculator.GetPCname
Return Environment.MachineName
End Function
Public Sub OpenPort() Implements ICalculator.OpenPort
'some code.
End Function
End Class
任何想法如何设法调用我的本地服务而不是服务器的 Windows 服务?
【问题讨论】: