繁体   English   中英

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

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

我在Windows服务中托管了WCF服务。 我想要做的是调用位于客户端PC上的Windows服务(WS)和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服务吗?

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

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

我建议创建其他Windows服务,该服务仅在服务器上运行并在lan机器上调用方法。

暂无
暂无

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

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