从另一台PC上使用WCF Windows服务

时间:2013-04-17 14:43:02

标签: c# wcf windows-services

我创建了一个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

3 个答案:

答案 0 :(得分:0)

您应该尝试在此处修改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>

答案 1 :(得分:0)

首先,在基地址上用pc1更改localhost,如

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

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

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

答案 2 :(得分:0)

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

相关问题