wcf将一个服务同时绑定到http和tcp的写法
2014-03-12 17:27
246 查看
服务器端:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="DCourtDbConStr" connectionString="IRyiHYdvR0dghJ+3ltmD04Hpzc1LZjqPu1H49+L4iGRsL93jzDrmhZ2Jt2KGX2vzZJRuL8SwNYhHcBUPrcVhareMc5FHq6oR1GKyzOTuYJCUB1wid/hFyZi8S+QVi/NsNcQwKzeddPoaZSCCWYQ4P8t5arJE2WgY" providerName="DbOle" />
</connectionStrings>
<system.serviceModel>
<services>
<service name="DCourt.Service.DcDataService">
<!-- 这里是用来绑定http访问方式的 -->
<endpoint address="" binding="basicHttpBinding" name="webIn"
contract="DCourt.Service.IDcDataService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<!-- 这里是用来绑定tcp访问方式的 -->
<endpoint address=""
binding="netTcpBinding"
contract="DCourt.Service.IDcDataService"/>
<endpoint address="mex" binding="mexHttpBinding" name="mexIn"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8001/DcService"/>
<add baseAddress="http://localhost:8000/DcService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- 为避免泄漏元数据信息,
请在部署前将以下值设置为 false -->
<serviceMetadata httpGetEnabled="True"/>
<!-- 要接收故障异常详细信息以进行调试,
请将以下值设置为 true。在部署前设置为 false
以避免泄漏异常信息 -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
客户端(通过8000端口或者8001端口都可以用,上面的服务器端配置同时绑定了HTTP 8000端口和TCP8001端口)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="DCourtDbConStr" connectionString="IRyiHYdvR0dghJ+3ltmD04Hpzc1LZjqPu1H49+L4iGRsL93jzDrmhZ2Jt2KGX2vzZJRuL8SwNYhHcBUPrcVhareMc5FHq6oR1GKyzOTuYJCUB1wid/hFyZi8S+QVi/NsNcQwKzeddPoaZSCCWYQ4P8t5arJE2WgY" providerName="DbOle" />
</connectionStrings>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IDcDataService">
<security mode="None">
<transport clientCredentialType="None" />
<message clientCredentialType="UserName" />
</security>
</binding>
</basicHttpBinding>
<netTcpBinding>
<binding name="NetTcpBinding_IDcDataService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8000/DcService/" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IDcDataService" contract="DcDataSer.IDcDataService"
name="BasicHttpBinding_IDcDataService" />
<endpoint address="net.tcp://localhost:8001/DcService" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IDcDataService" contract="DcDataSer.IDcDataService"
name="NetTcpBinding_IDcDataService" />
</client>
</system.serviceModel>
</configuration>
客户端代码
//using (DcDataServiceClient client = new DcDataServiceClient())//这个时候要注释掉其中一个endpoint
//using (DcDataServiceClient client = new DcDataServiceClient("NetTcpBinding_IDcDataService"))
using (DcDataServiceClient client = new DcDataServiceClient("NetTcpBinding_IDcDataService"))
{
DCArea[] lstAreas = client.GetAllDCAreas();
foreach (DCArea area in lstAreas)
{
ShowDbgInfo(area.DcName);
}
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="DCourtDbConStr" connectionString="IRyiHYdvR0dghJ+3ltmD04Hpzc1LZjqPu1H49+L4iGRsL93jzDrmhZ2Jt2KGX2vzZJRuL8SwNYhHcBUPrcVhareMc5FHq6oR1GKyzOTuYJCUB1wid/hFyZi8S+QVi/NsNcQwKzeddPoaZSCCWYQ4P8t5arJE2WgY" providerName="DbOle" />
</connectionStrings>
<system.serviceModel>
<services>
<service name="DCourt.Service.DcDataService">
<!-- 这里是用来绑定http访问方式的 -->
<endpoint address="" binding="basicHttpBinding" name="webIn"
contract="DCourt.Service.IDcDataService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<!-- 这里是用来绑定tcp访问方式的 -->
<endpoint address=""
binding="netTcpBinding"
contract="DCourt.Service.IDcDataService"/>
<endpoint address="mex" binding="mexHttpBinding" name="mexIn"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8001/DcService"/>
<add baseAddress="http://localhost:8000/DcService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- 为避免泄漏元数据信息,
请在部署前将以下值设置为 false -->
<serviceMetadata httpGetEnabled="True"/>
<!-- 要接收故障异常详细信息以进行调试,
请将以下值设置为 true。在部署前设置为 false
以避免泄漏异常信息 -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
客户端(通过8000端口或者8001端口都可以用,上面的服务器端配置同时绑定了HTTP 8000端口和TCP8001端口)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="DCourtDbConStr" connectionString="IRyiHYdvR0dghJ+3ltmD04Hpzc1LZjqPu1H49+L4iGRsL93jzDrmhZ2Jt2KGX2vzZJRuL8SwNYhHcBUPrcVhareMc5FHq6oR1GKyzOTuYJCUB1wid/hFyZi8S+QVi/NsNcQwKzeddPoaZSCCWYQ4P8t5arJE2WgY" providerName="DbOle" />
</connectionStrings>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IDcDataService">
<security mode="None">
<transport clientCredentialType="None" />
<message clientCredentialType="UserName" />
</security>
</binding>
</basicHttpBinding>
<netTcpBinding>
<binding name="NetTcpBinding_IDcDataService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8000/DcService/" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IDcDataService" contract="DcDataSer.IDcDataService"
name="BasicHttpBinding_IDcDataService" />
<endpoint address="net.tcp://localhost:8001/DcService" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IDcDataService" contract="DcDataSer.IDcDataService"
name="NetTcpBinding_IDcDataService" />
</client>
</system.serviceModel>
</configuration>
客户端代码
//using (DcDataServiceClient client = new DcDataServiceClient())//这个时候要注释掉其中一个endpoint
//using (DcDataServiceClient client = new DcDataServiceClient("NetTcpBinding_IDcDataService"))
using (DcDataServiceClient client = new DcDataServiceClient("NetTcpBinding_IDcDataService"))
{
DCArea[] lstAreas = client.GetAllDCAreas();
foreach (DCArea area in lstAreas)
{
ShowDbgInfo(area.DcName);
}
}
相关文章推荐
- 当Silverlight同时遇上TCP和Http的WCF服务
- 当Silverlight同时遇上TCP和Http的WCF服务
- 一起谈.NET技术,当Silverlight同时遇上TCP和HTTP的WCF服务
- WCF面向服务应用程序系列之十:绑定-标准绑定(HTTP/TCP)
- WCF 第四章 绑定 在多个绑定上暴露一个服务契约
- Golang1.7 Http和Tcp使用同一个端口做服务
- WCF技术剖析之二十七: 如何将一个服务发布成WSDL[基于HTTP-GET的实现](提供模拟程序)
- 化零为整WCF(3) - 绑定Binding(basicHttpBinding和netTcpBinding)
- 化零为整WCF(3) - 绑定Binding(basicHttpBinding和netTcpBinding)
- 化零为整WCF(3) - 绑定Binding(basicHttpBinding和netTcpBinding)
- 解决WCF“这可能是由于服务终结点绑定未使用 HTTP 协议造成的,这还可能是由于服务器中止了 HTTP 请求上下文(可能由于服务关闭)所致”异常
- WCF服务使用(IIS+Http)和(Winform宿主+Tcp)两种方式进行发布
- WCF并发(Concurrency)的本质:同一个服务实例上下文(InstanceContext)同时处理多个服务调用请求(转)
- WCF并发(Concurrency)的本质:同一个服务实例上下文(InstanceContext)同时处理多个服务调用请求
- WCF面向服务应用程序系列之十一:绑定-双向绑定(WSDualHttpBinding)
- 一个HttpClient使用Windows认证请求WCF服务的例子
- WCF并发(Concurrency)的本质:同一个服务实例上下文(InstanceContext)同时处理多个服务调用请求
- 测试wcf的http和tcp绑定以及非wcf的命名管道传输文件速度对比
- WCF技术剖析之二十七: 如何将一个服务发布成WSDL[基于HTTP-GET的实现](提供模拟程序)
- WCF 第四章 绑定 在多个绑定上暴露一个服务契约