2016-02-16 66 views
0

我有一個Windows服務中託管的WCF服務。我想要做的是調用位於客戶端PC和WS上的Windows服務(WS),以在同一客戶端計算機上調用客戶端DLL。 我已經在每臺客戶端PC和服務器上安裝了WS。當瀏覽服務器上的ASP.NET頁面並調用方法時,它可以正常工作,但客戶端PC不是從本地WS調用其DLL,而是調用服務器上調用的WS - 這不是期望的行爲。該環境將安裝在局域網上。WCF調用本地Windows服務而不是服務器的

我的一個示例方法是獲取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服務的?

回答

0

你應該在每檯安裝和配置了windows服務的網絡pc上調用方法,調用服務器上的方法意味着它只會在你的服務器上執行一次。您需要調用所有機器上的所有方法,如:

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

我建議創建不同的窗口服務,這隻會在服務器上運行,並調用你的局域網的機器的方法。

相關問題