WCF Service Base Address Http and netTcp

前端 未结 2 1265
时光说笑
时光说笑 2021-02-08 11:08

I have two base addresses defined in my WCF Service config file:


      
  

        
相关标签:
2条回答
  • 2021-02-08 11:36

    Due to not having answers clear enough , I decided to find out by my self the best solution. Here is what you have to do to configure a WCF NET TCP service endpoint in IIS 7.0.

    To achieve this, we need two steps:

    1. Configure a config file for WCF net tcp endpoint
    2. Configure IIS for net tcp

    1. Configure a config file for WCF net tcp endpoint

    Below is a typical config file, notice that the value for "address", in service's endpoint, is empty.

    Also notice that inside the node "host" Im adding 2 base addresses, an http and a net tcp protocols respectly. Since the service is hosted in IIS you don't have to worry about the absolute address in the endpoint, IIS figures this out based on the base address we have defined inside the node "host".

        <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="behaviorConfig">
              <!--your custom behavior here-->
            </behavior>
          </serviceBehaviors>
        </behaviors>
         <bindings>
          <basicHttpBinding>
            <binding name="basicHttpBindingConfig"/>
          </basicHttpBinding>
          <netTcpBinding>
            <!--our netTcpBinding binding-->
            <binding name="netTcpBindingConfig"/>   
          </netTcpBinding>
        </bindings>
        <services>
          <service name="MyNamespace.ServiceLayer.MyService" behaviorConfiguration="behaviorConfig">
            <!--Endpoint for basicHttpBinding-->
            <endpoint address="" binding="basicHttpBinding" contract="MyNamespace.ServiceLayer.IMyService" bindingConfiguration="basicHttpBindingConfig"/>
            <!--Endpoint for netTcpBindingConfig-->
            <endpoint address="" binding="netTcpBinding" contract="MyNamespace.ServiceLayer.IMyService" bindingConfiguration="netTcpBindingConfig">
            <identity>
                <dns value="localhost" />
            </identity>
        </endpoint>
        <!--Make sure you add a mexTcpBinding, without it you will receive an error when trying to resolve service's reference-->
        <endpoint address="mex" 
                  binding="mexTcpBinding" 
                  bindingConfiguration=""
                  name="MyServiceMexTcpBidingEndpoint" 
                  contract="IMetadataExchange" />
            <host>
                <!--This part is important for IIS to determine the base addresses for your endpoints-->
                <baseAddresses>            
                     <!--Notice that baseAddress for net tcp is preceded by net.tcp -->
                     <!--then ://localhost:{port} -->
                     <!--Also the same for http, so you can figure out how to define a baseAddress for https-->
                   <add baseAddress="net.tcp://localhost:8090"/>
                   <add baseAddress="http://localhost:8080"/>
                </baseAddresses>
            </host>
          </service>
        </services>    
      </system.serviceModel>
    

    2. Configure IIS for net tcp

    In IIS, (after updated your service with new configuration) enable the net.tcp protocol. These are the steps:

    • Open IIS.
    • In sites list, find your "site" where your wcf is hosted, then right-click on it
    • then, select "Edit Bindings",
    • a list of bindings appears (be sure that net.tcp is no there), then add your net.tcp configuration,
    • click "Add",
    • Type net.tcp (or select net.tcp from a dropdown list if it is available)
    • in binding Information type: 8090:* (make sure it's the same port as in host > base address you'd added)
    • then close this window and restart your service.

    After doing this, there is also another configuration:

    • Open IIS
    • In sites list, find your "site" where your wcf is hosted, then right-click on it
    • Click "Advanced Settings"
    • Select Enabled Protocols
    • Set the value to http,net.tcp (be sure that there are not blanks between http,net.tcp)
    • Restart your service

    Also, if you still cannot access service, you might need to start your Net.tcp listener adapter in your server. To achieve this, please follow next steps:

    • Go to ServerManager -> Configuration -> Services, stop the Net.Tcp Listener Adapter and the Net.Tcp Port Sharing Service. Then start them again.

    That's all you have to do to have a nettcp WCF endpoint enabled in IIS.

    Hope this helps.

    Regards

    0 讨论(0)
  • 2021-02-08 11:42

    You defined a Net.TCP base address to be:

    net.tcp://localhost:8001/TemplateReportService
    

    Your endpoints with Net TCP are:

    <endpoint address="TemplateService" 
    

    and

    <endpoint address="ReportService" 
    

    So their complete service address will be "netTcp base address" + "relative address as defined on the <endpoint> element" - this gives:

    net.tcp://localhost:8001/TemplateReportService/TemplateService
    

    and

    net.tcp://localhost:8001/TemplateReportService/ReportService
    

    respectfully.

    Can you use them at these addresses??

    Also - you defined a "mex" (metadata exchange) endpoint for the HTTP protocol - that's why you can see something when you navigate to the HTTP address. But you did not specify a MEX endpoint for netTcp.

    0 讨论(0)
提交回复
热议问题