NET TCP/HTTP WCF Hosted in IIS
Asked Answered
P

1

7

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!

Plaintive answered 10/7, 2012 at 12:33 Comment(0)
C
14
  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>
Crotch answered 10/7, 2012 at 12:50 Comment(11)
Thanks for the quick reply. I already had the bindings enabled, and I just added the host base address to my config file where the baseAddress="net.tcp://localhost:12345/EdWCF.svc" - still not able to connect.Plaintive
You need to add full address. If EdWCF.svc is in Engine folder change it to net.tcp://localhost:12345/Engine/EdWCF.svcCrotch
I have the Physical Path of my IIS Application set to C:\User\WCF\WCF thats where the EdWCF.svc file is located. I adjusted the base address to have net.tcp://localhost:12345/WCF/EdWCF.svc but when I try to connect from our client I still get : Could not connect to net.tcp://localhost:12345/WCF/EdWCF.svc. The connection attempt lasted for a time span of 00:00:02.0052005. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:12345.Plaintive
Thanks so much for taking the time out to try and help me troubleshoot this issue. I appreciate it very much. Unfortunately I'm still not having any luck. I get the same "connection refused" error message. I changed my config file to match the one you posted but for some reason, My connection isn't getting established. I double checked my bindings and NetTCP is listed and is an enabled protocol.Plaintive
The physical path of my IIS application is C:\Franco Projects\WCF\WCF - EdWCF.svc and an EdWCF.svc.cs file in that directory. I modified my .svc file to have <%@ ServiceHost Language="C#" Debug="true" Service="TwoFour.WCF.Engine.EdWCF" CodeBehind="EdWCF.svc.cs" %>. Not sure what part of my configuration is causing the connection to be refused.Plaintive
CodeBehind="EdWCF.svc.cs" should be CodeBehind="TwoFour.WCF.Engine.EdWCF.svc.cs" if EdWCF class is in 'TwoFour.WCF.Engine' namespace.Crotch
Also please try to change mexTcpBinding to mexHttpBinding and add <serviceMetadata HttpGetEnabled="True" /> Let me know if it helpsCrotch
I edited My original post with my new Web.Config file. After changing it, I get a new error message. Did I incorrectly edit the file? Now when trying to connect from my client I get: Message: Unrecognized configuration section system.serviceModel/service. (C:\Franco Projects\WCF\WCF\web.config line 13)Plaintive
Hm, still the same message. I tried removing that line entirely and I still got the same message pointing at the same line. Aside from adding that, I also changed the mexTcpBinding as you instructed, not sure if that's the problem. Again, thanks so much for the time and effort you've put in to help me.Plaintive
In your config <services> </services> are missing :) So it should be <services> <service>...</service> </services>Crotch
I had to remove the HttpGetEnabled="true" because it kept saying it was an unrecognized attribute but after I did that, I was finally able to connect. Thanks so much buddy, your the man!Plaintive

© 2022 - 2024 — McMap. All rights reserved.