【问题标题】:WCF Calling local Windows Service and not server'sWCF 调用本地 Windows 服务而不是服务器的
【发布时间】: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 服务?

【问题讨论】:

    标签: c# vb.net wcf


    【解决方案1】:

    您应该在每台已安装和配置 Windows 服务的网络 PC 上调用方法,在您的服务器上调用方法意味着它只会在您的服务器上执行一次。您需要在所有机器上调用所有方法,例如:

    192.168.1.1\MyWindowsService\Method1
    192.168.1.2\MyWindowsService\Method1
    ...
    etc.
    

    我建议创建不同的 windows 服务,它只在服务器上运行并在你的局域网机器上调用方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-19
      • 2015-07-22
      • 1970-01-01
      • 1970-01-01
      • 2017-04-09
      • 2012-06-14
      • 1970-01-01
      相关资源
      最近更新 更多