简体   繁体   English

WCF调用本地Windows服务而不是服务器的

[英]WCF Calling local Windows Service and not server's

I have a WCF service hosted in a Windows Service. 我在Windows服务中托管了WCF服务。 What I am trying to do is to call the Windows Service (WS) which is situated on the client PC and the WS to call a client DLL on the same client computer. 我想要做的是调用位于客户端PC上的Windows服务(WS)和WS,以在同一台客户端计算机上调用客户端DLL。 I have installed the WS on each client PC and on the server. 我已经在每台客户端PC和服务器上安装了WS。 When navigating to the ASP.NET page on the server and I invoke the method, it works fine, but the client PCs instead of calling their DLLs from their local WS, they call the WS that is called on the server - which is not the desired behavior. 当导航到服务器上的ASP.NET页并调用该方法时,它可以正常工作,但是客户端PC而不是从其本地WS调用其DLL,而是调用在服务器上调用的WS-而不是期望的行为。 This environment will be installed on a LAN. 该环境将安装在LAN上。

An example method I have is to get the PCs name, which wrongly in return I get the server's name. 我拥有的示例方法是获取PC名称,这反过来又得到了服务器名称。

This is my app.config file: 这是我的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>

My service class: 我的服务等级:

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

Any ideas how to manage to call my LOCAL service instead of the server's Windows Service? 有什么想法如何设法调用本地服务而不是服务器的Windows服务吗?

You should invoke method on every network pc with installed and configured windows services, invoking method on your server means that it will be executed only once and only on your server. 您应该在安装并配置了Windows服务的每台网络PC上调用method,在服务器上调用method意味着该方法只能在服务器上执行一次。 You need to invoke all your methods on all machines, like: 您需要在所有计算机上调用所有方法,例如:

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

I suggest to create different windows service, which would run only on server and invoke methods on your lan machines. 我建议创建其他Windows服务,该服务仅在服务器上运行并在lan机器上调用方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM