NET TCP/HTTP WCF Hosted in IIS

北战南征 提交于 2019-12-09 11:29:33

问题


I'm new to WCF and IIS but been doing some reading on how to host a WCF application in IIS. We have a system we're trying to deploy to IIS which needs HTTP and NET.TCP endpoints. I have everything configured as I saw in random tutorials but I still can't connect from my client. Any help with the configuration would be greatly appreciated!

My EdWCF.svc file in my WCF directory:

< %@ ServiceHost Language="C#" Debug="true" Service="TwoFour.WCF.Engine.EdWCF" % >

My Web.Config:

    <?xml version="1.0"?>
<configuration>
<system.serviceModel>

    <behaviors>
      <serviceBehaviors>
        <behavior name="MyBehaviour">
          <serviceMetadata HttpGetEnabled="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

<service name="TwoFour.WCF.Engine.EdWCF" behaviorConfiguration="MyBehaviour">
       <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:12345/WCF/EdWCF.svc"/>
          </baseAddresses>
       </host>
       <endpoint address=""
                 binding="netTcpBinding"
                 bindingConfiguration="InsecureTcp"
                 contract="TwoFour.WCF.Interface.Shared.IEdWCF" />
       <endpoint address="mexhttp" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>

  <bindings>
            <netTcpBinding>
                <binding name="InsecureTcp" portSharingEnabled="true">
                    <security mode="None" />
                </binding>
            </netTcpBinding>
        </bindings>

</system.serviceModel>

</configuration>

Thanks for any help or suggestions!


回答1:


  1. In IIS add net.tcp binding into enabled protocols list (Mange Web Site -> Advance Settings -> Enabled Protocols)

  2. In Site binding add net.tcp binding (Edit Binding -> Add -> Choose type as net.tcp and add port like this 12345:*)

You also need to specify Base address in your config:

<system.serviceModel>
 <services>
     <host>
       <baseAddresses>
         <add baseAddress="net.tcp://server:12345/ServiceAddress.svc"/>
       </baseAddresses>
     </host>
     ...
 </service>
     ...
</system.serviceModel>

Edit:

Try this

<system.serviceModel>

    <behaviors>
      <serviceBehaviors>
        <behavior name="MyBehaviour">
          <serviceMetadata />
        </behavior>
      </serviceBehaviors>
    </behaviors>

<service name="TwoFour.WCF.Engine.EdWCF" behaviorConfiguration="MyBehaviour">
       <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:12345/WCF/EdWCF.svc"/>
          </baseAddresses>
       </host>
       <endpoint address=""
                 binding="netTcpBinding"
                 bindingConfiguration="InsecureTcp"
                 contract="TwoFour.WCF.Interface.Shared.IEdWCF" />
       <endpoint address="mextcp" binding="mexTcpBinding" contract="IMetadataExchange"/>
</service>

  <bindings>
            <netTcpBinding>
                <binding name="InsecureTcp" portSharingEnabled="true">
                    <security mode="None" />
                </binding>
            </netTcpBinding>
        </bindings>

</system.serviceModel>


来源:https://stackoverflow.com/questions/11413406/net-tcp-http-wcf-hosted-in-iis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!