首先我创建一个创建svc文件的WCF服务应用程序。然后我写了我的小服务相关代码。 当我点击F5然后wcf测试客户端显示正常,当我选择svc文件并在浏览器选项中选择视图时,一切正常。最初我在配置文件中只有一个端点... wsDualHttpBinding 然后一切正常。
当我添加另一个名为 netTcpBinding 的端点然后问题开始。在配置文件中添加netTcpBinding端点后,当我尝试在浏览器中再次浏览svc文件时,我收到错误消息“协议'net.tcp'不支持当我点击F5然后wcf测试客户端显示名为** Cannot obtain Metadata from http://localhost:30996/ChatService.svc**
我只是不明白为什么当我添加netTcpBinding时会发生这种情况。我喜欢说我没有在任何地方托管我的服务。我只是创建WCF服务应用程序并添加web.config文件中的所有条目,然后按F5。这是我收到错误的原因,因为我没有在任何地方托管我的服务?
所以这是我的配置详情如下
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="BBAChatService.ChatService" behaviorConfiguration="BBAChatService.ChatServiceBehavior" >
<host>
<baseAddresses>
<add baseAddress ="http://localhost:30996/ChatService.svc/"/>
<add baseAddress ="net.tcp://localhost:30997/ChatService/"/>
</baseAddresses>
</host>
<endpoint name="dual_bind"
address="dual"
binding="wsDualHttpBinding"
bindingConfiguration="WSDualHttpBinding_IChatService"
contract="BBAChatService.IChatService">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint name="tcp_bind"
address="net.tcp://localhost:30997/ChatService"
binding="netTcpBinding"
bindingConfiguration="tcpBinding"
contract="BBAChatService.IChatService">
</endpoint>
<endpoint address="net.tcp://localhost:30997/ChatService/mex"
binding="mexTcpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="BBAChatService.ChatServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="tcpBinding"
maxBufferSize="67108864"
maxReceivedMessageSize="67108864"
maxBufferPoolSize="67108864"
transferMode="Buffered"
closeTimeout="00:00:10"
openTimeout="00:00:10"
receiveTimeout="00:20:00"
sendTimeout="00:01:00"
portSharingEnabled="true"
maxConnections="100">
<security mode="None">
</security>
<readerQuotas maxArrayLength="67108864"
maxBytesPerRead="67108864"
maxStringContentLength="67108864"/>
<reliableSession enabled="true" inactivityTimeout="00:20:00"/>
</binding>
</netTcpBinding>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IChatService"
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:01:00"
bypassProxyOnLocal="false"
transactionFlow="false"
hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288"
maxReceivedMessageSize="65536"
messageEncoding="Text"
textEncoding="utf-8"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32"
maxStringContentLength="8192"
maxArrayLength="16384"
maxBytesPerRead="4096"
maxNameTableCharCount="16384"/>
<reliableSession
ordered="true"
inactivityTimeout="00:10:00"/>
<security mode="Message">
<message clientCredentialType="Windows"
negotiateServiceCredential="true"
algorithmSuite="Default"/>
</security>
</binding>
</wsDualHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
告诉我缺少什么......我需要在配置文件中更改内容。
这是我的项目解决方案资源管理器的屏幕截图。
答案 0 :(得分:2)
当您点击F5时,VS使用的内置Web服务器仅支持HTTP激活,因此您将无法在其中托管net.tcp端点。你可以:
正确托管服务后,您必须为其创建元数据交换端点(绑定类型为mexTcpBinding),并在网络的行为配置中将httpGetEnabled
设置为false
。 tcp端点。
编辑: 有关WcfSvcHost.exe的详细用法说明,请参阅this msdn article。对于httpGetEnabled,我打算在net.tcp服务端点的行为中将serviceMetadata设置为false。
<serviceBehaviors>
<behavior name="BehaviorName">
<serviceMetadata httpGetEnabled="false" />
</behavior>
<serviceBehaviors>
然后将此行为应用于net.tcp端点。我假设您希望通过TCP(而不是HTTP)为此端点公开元数据,在这种情况下,您需要包含一个mexTcpBinding端点。