【问题标题】:cosume a WCF windows service from another PC从另一台 PC 使用 WCF Windows 服务
【发布时间】:2013-04-17 14:43:02
【问题描述】:

我创建了 WCF 服务并将其托管在 Windows 服务中。使用 Visual Studio 测试此服务效果很好,我可以使用它。现在我已经在一台 PC(称为 PC1)上安装了该服务,并使用另一台 PC(称为 PC2)我希望能够发现它并使用它。我想我将不得不修改 app.config 文件来实现这一点。

这是我当前的 app.config,我需要修改什么才能使其在其他联网计算机上运行?我猜基地址是一个开始?

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<appSettings>
  <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
  <compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
  <services>      
  <service name="WcfAVOLibrary.AVOs">
    <endpoint address="" binding="wsDualHttpBinding" contract="WcfAVOLibrary.IAVOs">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8733/Design_Time_Addresses/WcfAVOLibrary/AVOs/" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, 
      set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="True"/>
      <!-- To receive exception details in faults for debugging purposes, 
      set the value below to true.  Set to false before deployment 
      to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="False" />
    </behavior>
  </serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

哦,我正在运行 .Net 4.5

【问题讨论】:

    标签: c# wcf windows-services


    【解决方案1】:

    你应该尝试在这个地方修改web.config:

      <baseAddresses>
        <add baseAddress="http://192.168.1.2/Design_Time_Addresses/WcfAVOLibrary/AVOs/" />
      </baseAddresses>
    

    其中 192.168.1.2 是您当前的 ip,或者 localhost 也可以,它会如下所示:

      <baseAddresses>
        <add baseAddress="http://localhost/Design_Time_Addresses/WcfAVOLibrary/AVOs/" />
      </baseAddresses>
    

    【讨论】:

    • 这是一个 Windows 服务,而不是一个 Web 服务
    【解决方案2】:

    首先,在基地址上通过 pc1 更改 localhost,例如

    http://pc1:8733/Design_Time_Addresses/WcfAVOLibrary/AVOs/

    之后,尝试从 pc2 上的浏览​​器打开基地址 url(是的,别介意它是 win.service - 这是您的服务 url,应该可以访问)。应该没问题,在你开始工作之前你不需要继续。

    完成后 - 检查客户端的配置以匹配服务地址。

    【讨论】:

    • 我在另一台 PC 上尝试了该地址,但无法正常工作。
    【解决方案3】:

    面临同样的问题。添加入站规则以在 Windows 防火墙中打开端口 8733。成功了!

    【讨论】:

      猜你喜欢
      • 2013-01-24
      • 1970-01-01
      • 1970-01-01
      • 2021-03-05
      • 1970-01-01
      • 1970-01-01
      • 2011-09-10
      • 2011-01-31
      • 2020-11-19
      相关资源
      最近更新 更多