2010-01-06 101 views
10

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

<?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服务与基地地址:

http://localhost:8181/TemplateReportService 

,而不是与

net.tcp://localhost:8001/TemplateReportService 

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

回答

15

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

net.tcp://localhost:8001/TemplateReportService 

您与网络TCP端点是:

<endpoint address="TemplateService" 

<endpoint address="ReportService" 

所以其完整的服务地址会是“netTcp基地址”+“在<endpoint>元素上定义的相对地址” - 这给出:

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

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

恭敬。

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

而且 - 你定义的“MEX”(元数据交换),HTTP协议终点 - 这就是为什么你可以看到的东西,当你浏览到HTTP地址。但是您没有为netTcp指定MEX端点。

+0

谢谢你马克,因此,它的意思是,即使我已NetTcpBinding的两个端点,但如果我有元数据暴露HttpBinding,它会在HTTP地址公开服务。 – iniki 2010-01-06 12:46:18

+0

它将在http地址处公开服务的元数据 - 这意味着您只能使用浏览器在那里浏览。 NetTcp端点处于活动状态,随时可以使用 - 您无法通过浏览器访问任何内容... – 2010-01-06 14:34:41

1

由于没有明确的答案,够了,我决定由我自己最好的解决办法,找出。以下是在IIS 7.0中配置WCF NET TCP服务端点所必须做的事情。

为了实现这一目标,我们需要两个步骤:

  1. 配置为WCF网的TCP端点配置文件
  2. 配置IIS净TCP

1.配置一个配置文件为WCF网的TCP端点

下面是一个典型的配置文件,请注意,对于值“加ress“在服务的端点中是空的。

还要注意,节点“宿主”内部林加入2个基地址,一个HTTP和TCP净协议respectly。由于该服务托管在IIS您不必担心在端点上的绝对地址,IIS数据基础上,基址了这一点,我们的节点“主机”中定义。

<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.配置IIS净TCP

在IIS中,(更新后新的配置为您服务)启用的net.tcp协议。这些是步骤:

  • 打开IIS。
  • 在站点列表中,找到您的WCF托管你的“地盘”,然后在其上单击鼠标右键
  • 然后,选择“编辑绑定”,
  • 绑定列表出现(确保的net.tcp不存在),然后添加您的net.tcp配置,
  • 单击绑定信息类型“添加”,
  • 类型的net.tcp(或从下拉列表中选择的net.tcp如果可用)
  • :8090:*(确保它与您添加的主机>基地址相同的端口)
  • 然后关闭此窗口并重新启动您的服务。

这样做了以后,也有另一种配置:

  • 打开IIS
  • 在站点列表中,找到您的WCF托管你的“地盘”,然后在其上
  • 右击
  • 点击“高级设置”
  • 选择启用的协议
  • 将值设置为HTTP,的net.tcp(确保不会有之间的HTTP,空白的net.tcp)
  • 重新启动服务

另外,如果你仍然无法访问服务,您可能需要启动的net.tcp侦听器适配器在您的服务器。要达到此目的,请按照下列步骤操作:

  • 转到ServerManager→配置→服务,停止Net.Tcp侦听器适配器和Net.Tcp端口共享服务。然后再次启动它们。

这就是为了在IIS中启用nettcp WCF端点而必须做的所有事情。

希望这会有所帮助。

问候

+0

在http://stackoverflow.com/questions/18575496中未理解您关于我的答案的编辑/ could-not-find-a-base-address-that-matches-scheme-net-tcp-for-the-the-endpoint-with/18575819#18575819检查你的状态,然后再提升他们。 IIS6不支持NET.TCP!请参阅http://msdn.microsoft.com/en-us/library/ms730158.aspx – Alex 2014-07-25 10:48:21