[英]WCF Service Base Address Http and netTcp
I have two base addresses defined in my WCF Service config file: 我在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>
And although I have set endpoint binding as netTcpBinding, 虽然我已将端点绑定设置为netTcpBinding,
I am only able to access my WCF service with base address: 我只能使用基地址访问我的WCF服务:
http://localhost:8181/TemplateReportService
and not with 而不是
net.tcp://localhost:8001/TemplateReportService
How can I make my service access with netTcp address? 如何使用netTcp地址进行服务访问?
You defined a Net.TCP base address to be: 您将Net.TCP基地址定义为:
net.tcp://localhost:8001/TemplateReportService
Your endpoints with Net TCP are: 您使用Net TCP的端点是:
<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: 因此,他们的完整服务地址将是“netTcp基地址”+“
<endpoint>
元素上定义的相对地址” - 这给出:
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. 此外 - 您为HTTP协议定义了一个“mex”(元数据交换)端点 - 这就是您导航到HTTP地址时可以看到某些内容的原因。 But you did not specify a MEX endpoint for netTcp.
但是您没有为netTcp指定MEX端点。
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.
以下是在IIS 7.0中配置WCF NET TCP服务端点所需执行的操作。
To achieve this, we need two steps: 为实现这一目标,我们需要两个步骤:
1. Configure a config file for WCF net tcp endpoint 1.为WCF net tcp端点配置配置文件
Below is a typical config file, notice that the value for "address", in service's endpoint, is empty. 下面是一个典型的配置文件,请注意服务端点中“address”的值为空。
Also notice that inside the node "host" Im adding 2 base addresses, an http and a net tcp protocols respectly. 另请注意,在节点“host”中,我添加了2个基本地址,http和net tcp协议。 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".
由于服务是在IIS中托管的,因此您不必担心端点中的绝对地址,IIS会根据我们在节点“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 2.为net tcp配置IIS
In IIS, (after updated your service with new configuration) enable the net.tcp protocol. 在IIS中,(在使用新配置更新服务之后)启用net.tcp协议。 These are the steps:
这些是步骤:
After doing this, there is also another configuration: 执行此操作后,还有另一种配置:
Also, if you still cannot access service, you might need to start your Net.tcp listener adapter in your server. 此外,如果仍然无法访问服务,则可能需要在服务器中启动Net.tcp侦听器适配器。 To achieve this, please follow next steps:
为此,请按照以下步骤操作:
That's all you have to do to have a nettcp WCF endpoint enabled in IIS. 这就是在IIS中启用nettcp WCF端点所需要做的全部工作。
Hope this helps. 希望这可以帮助。
Regards 问候
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.