WCF服务基地地址http和netTcp地址、基地、WCF、http

2023-09-03 06:28:33 作者:中国逗比代表

我有我的WCF服务配置文件定义了两个基地地址:

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

<?xml version="1.0" encoding="utf-8" ?>
<configuration>      
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Warning, ActivityTracing"
        propagateActivity="true">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="ServiceModelTraceListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="C:\WCF Service Logs\app_tracelog.svclog"
        type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
        name="ServiceModelTraceListener" traceOutputOptions="DateTime, Timestamp">
        <filter type="" />
      </add>
    </sharedListeners>
  </system.diagnostics>
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="netTcp" maxBufferPoolSize="50000000" maxReceivedMessageSize="50000000">
          <readerQuotas maxDepth="500" maxStringContentLength="50000000" maxArrayLength="50000000" maxBytesPerRead="50000000" maxNameTableCharCount="50000000" />
          <security mode="None"></security>
        </binding>
      </netTcpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior"
        name="ReportingComponentLibrary.TemplateReportService">
        <endpoint address="TemplateService" binding="netTcpBinding" bindingConfiguration="netTcp"
          contract="ReportingComponentLibrary.ITemplateService"></endpoint>
        <endpoint address="ReportService" binding="netTcpBinding" bindingConfiguration="netTcp"
          contract="ReportingComponentLibrary.IReportService"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:8001/TemplateReportService" />
            <add baseAddress="http://localhost:8181/TemplateReportService"  />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ReportingComponentLibrary.TemplateServiceBehavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

虽然我已经设置终点为NetTcpBinding的结合, 我只能够与基址访问我的WCF服务:

And although I have set endpoint binding as netTcpBinding, I am only able to access my WCF service with base address:

http://localhost:8181/TemplateReportService

而不是

net.tcp://localhost:8001/TemplateReportService

我如何可以与netTcp我的业务接入解决?

How can I make my service access with netTcp address?

推荐答案

您定义的基础的net.tcp地址是:

You defined a Net.TCP base address to be:

net.tcp://localhost:8001/TemplateReportService

您的端点与网络的TCP是:

Your endpoints with Net TCP are:

<endpoint address="TemplateService" 

<endpoint address="ReportService" 

所以他们的完整的服务地址将是netTcp基地址+相对作为定义地址&LT;端点&GT; 元素 - 这给:

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

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

尊敬。

您可以用它们在这些地址??

Can you use them at these addresses??

另外 - 你所定义的MEX(元数据交换)端点HTTP协议 - 这就是为什么你可以看到的东西,当你浏览到HTTP地址。但是你没有指定一个MEX端点netTcp。

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.