简体   繁体   English

WCF Windows服务是否支持Intranet连接?

[英]Does WCF windows service support intranet connection?

I'm a beginner of WCF. 我是WCF的初学者。 I tried to host my WCF server in IIS and can succeed to visit the service in another machine. 我试图将WCF服务器托管在IIS中,并且可以成功访问另一台计算机上的服务。 When I change to host this WCF server in Windows Service, I can visit in local, but failed in another machine. 当我更改为在Windows Service中托管此WCF服务器时,可以在本地访问,但在另一台计算机上访问失败。 Does WCF support this? WCF支持吗? If there is any example to demo how to use windows service hosted WCF in Intranet, that will be appreciated! 如果有任何示例演示如何在Intranet中使用Windows服务托管的WCF,将不胜感激!

I have closed firewall on both machines. 我在两台计算机上都关闭了防火墙。 Below is the service config I used: 以下是我使用的服务配置:

<system.serviceModel>
  <services>
    <service behaviorConfiguration="Service" name="TestService.Test">
      <endpoint address="basic" binding="basicHttpBinding" name="basic" contract="TestService.ITest">
        <identity>
          <dns value="localhost"/>
        </identity>
      </endpoint>
      <endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange"/>
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:8080/TestService/"/>
        </baseAddresses>
      </host>
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="Service">
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="false"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>

@Rahul, thanks your help. @Rahul,谢谢您的帮助。 Finally I succeed. 终于我成功了。 Here I paste my configuration, hope can help someone who meet similar problem. 在这里粘贴我的配置,希望能对遇到类似问题的人有所帮助。 Change my server config to: 将我的服务器配置更改为:

<system.serviceModel>
<bindings>
  <netTcpBinding>
    <binding name="tcpConfig">
      <security mode="None" />
    </binding>
  </netTcpBinding>
</bindings>
<services>
  <service behaviorConfiguration="Service" name="TestService.Test">
    <endpoint address="net.tcp://localhost:8081/Test" binding="netTcpBinding"
      bindingConfiguration="tcpConfig" name="tcp" contract="TestService.ITest" />
    <endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8080/TestService/" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="Service">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

And below is my client config, which run on another machine: 下面是我的客户端配置,该配置在另一台计算机上运行:

<system.serviceModel>
    <bindings>
        <netTcpBinding>
            <binding name="tcp">
                <security mode="None" />
            </binding>
        </netTcpBinding>
    </bindings>
    <client>
        <endpoint address="net.tcp://192.168.209.132:8081/TestService" binding="netTcpBinding"
            bindingConfiguration="tcp" contract="TestServiceReference.ITest"
            name="tcp" />
    </client>
</system.serviceModel>

If it's intranet service and if you choose to deploy as windows service then consider using netTcpBinding like 如果是Intranet服务,并且您选择部署为Windows服务,则可以考虑使用netTcpBinding

binding="netTcpBinding"

Also, consider using proper IPv4 address of your machine rather than localhost 另外,请考虑使用计算机的正确IPv4地址而不是localhost

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

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