我的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>
虽然我已将端点绑定设置为netTcpBinding,但是 我只能使用基地址访问我的WCF服务:
http://localhost:8181/TemplateReportService
而不是
net.tcp://localhost:8001/TemplateReportService
如何使用netTcp地址进行服务访问?
答案 0 :(得分:16)
您将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协议定义了一个“mex”(元数据交换)端点 - 这就是您在导航到HTTP地址时可以看到某些内容的原因。但是您没有为netTcp指定MEX端点。
答案 1 :(得分:1)
由于答案不够明确,我决定自己找出最好的解决方案。以下是在 IIS 7.0中配置WCF NET TCP服务端点所需执行的操作。
为实现这一目标,我们需要两个步骤:
<强> 1。为WCF net tcp endpoint配置配置文件
以下是典型的配置文件,请注意服务终端中&#34;地址&#34;的值为空。
还要注意节点内部&#34;主机&#34;我加入了2个基地址,一个http和一个net tcp协议。由于服务是在IIS中托管的,因此您不必担心端点中的绝对地址,IIS会根据我们在节点&#34; host&#34;中定义的基址来解决这个问题。
<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。为net tcp配置IIS
在IIS中,(使用新配置更新服务后)启用net.tcp协议。这些是步骤:
执行此操作后,还有另一种配置:
此外,如果仍然无法访问服务,则可能需要在服务器中启动Net.tcp侦听器适配器。为此,请按照以下步骤操作:
您需要做的就是在IIS中启用nettcp WCF端点。
希望这有帮助。
此致