我完全是新手,想使用net.tcp绑定托管最简单的WCF服务。我有Windows 7专业版和IIS7,并启用了非HTTP激活。
- 我在vs2010中开始一个新的WCF服务应用程序项目并编译它。仅此而已!
- 我删除了所有的IIS网站,并添加了一个名为WCFHost的新网站。
- 我打开WcfTestClient.exe并添加了http://localhost/Service1.svc,应用程序找到了它。
Web.config文件如下(未更改)
<system.serviceModel>
<services>
<service name="WcfService2.Service1" behaviorConfiguration="WcfService2.Service1Behavior">
<endpoint address="" binding="wsHttpBinding" contract="WcfService2.IService1">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService2.Service1Behavior">
<!-- 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>
</system.serviceModel>
到目前为止,一切都很好。但是net.tcp绑定怎么样呢?我添加了“enabledProtocols”属性,所以我的applicationHost.config文件如下:
<site name="WCFHOST" id="3">
<application path="/" applicationPool="WCFHOST" enabledProtocols="http,net.tcp,net.pipe,net.msmq">
<virtualDirectory path="/" physicalPath="C:\Prosjekter\temp\TestService\TestService" />
</application>
<bindings>
<binding protocol="net.tcp" bindingInformation="808:*" />
<binding protocol="http" bindingInformation="*:80:" />
</bindings>
</site>
接下来,我前往IIS WCFHost网站并添加绑定net.tcp 808:* 然后,我修改了WCF服务的web.config,使其如下所示(仅更改了端点上的绑定)
<system.serviceModel>
<services>
<service name="WcfService2.Service1" behaviorConfiguration="WcfService2.Service1Behavior">
<!-- Service Endpoints -->
<endpoint address="" binding="netTcpBinding" contract="WcfService2.IService1">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService2.Service1Behavior">
<!-- 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>
</system.serviceModel>
当我现在尝试在我的WcfTestClient.exe中添加服务net.tcp://localhost:808/Service1.svc时,我遇到了错误:
错误:无法从net.tcp://localhost/Service1.svc获取元数据 TCP错误代码10061:无法建立连接,因为目标计算机积极拒绝.. 127.0.0.1:808
我的防火墙已关闭。 我看到一件事,当我使用netstat -a时,808端口没有列在那里.. 这是应该的吗?
有人可以帮我创建第一个使用nettcp绑定的WCF服务吗?