.net - WCF 服务基地址 Http 和 netTcp

标签 .net net.tcp wcf

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

<?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>

虽然我已经将端点绑定(bind)设置为 netTcpBinding,
我只能使用基地址访问我的 WCF 服务:
http://localhost:8181/TemplateReportService

而不是
net.tcp://localhost:8001/TemplateReportService

如何使用 netTcp 地址访问我的服务?

最佳答案

您将 Net.TCP 基地址定义为:

net.tcp://localhost:8001/TemplateReportService

您使用 Net TCP 的端点是:
<endpoint address="TemplateService" 


<endpoint address="ReportService" 

因此,它们的完整服务地址将是“netTcp 基地址”+“<endpoint> 元素上定义的相对地址” - 这给出:
net.tcp://localhost:8001/TemplateReportService/TemplateService


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

尊敬。

你可以在这些地址使用它们吗?

此外 - 您为 HTTP 协议(protocol)定义了一个“mex”(元数据交换)端点 - 这就是为什么您在导航到 HTTP 地址时可以看到一些东西的原因。但是您没有为 netTcp 指定 MEX 端点。

关于.net - WCF 服务基地址 Http 和 netTcp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2012765/

相关文章:

.net - 无法在运行时向 XML 添加命名空间

c# - 是否有超过 4 个参数的 Func 对象?

WCF net.tcp 绑定(bind)、消息格式和安全问题

.net - IIS 7 上的 net.tcp WCF 服务(mex 终结点)出现 "There is no compatible TransportManager found"错误

c# - WebGet 在功能上是否等同于 WebInvoke(Method = "GET")?

.net - IDisposable.Dispose() 未在异步方法的 Release模式下调用

c# - 为什么 EF 在第一次调用方法中需要很长时间

win7 上的 WCF Duplex net.tcp 问题

.net - 通过 HTTP 将用户名和密码以明文形式发送到 Web 服务

wcf - 如何为新的Silverlight应用程序在WCF,REST,POX和RIA服务之间进行选择