服务器端:
<?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);
                }
            }

wcf将一个服务同时绑定到http和tcp的写法的更多相关文章

  1. WCF技术剖析之二十七: 如何将一个服务发布成WSDL[基于HTTP-GET的实现](提供模拟程序)

    原文:WCF技术剖析之二十七: 如何将一个服务发布成WSDL[基于HTTP-GET的实现](提供模拟程序) 基于HTTP-GET的元数据发布方式与基于WS-MEX原理类似,但是ServiceMetad ...

  2. WCF技术剖析之二十七: 如何将一个服务发布成WSDL[基于WS-MEX的实现](提供模拟程序)

    原文:WCF技术剖析之二十七: 如何将一个服务发布成WSDL[基于WS-MEX的实现](提供模拟程序) 通过<如何将一个服务发布成WSDL[编程篇]>的介绍我们知道了如何可以通过编程或者配 ...

  3. WCF技术剖析之二十七: 如何将一个服务发布成WSDL[编程篇]

    原文:WCF技术剖析之二十七: 如何将一个服务发布成WSDL[编程篇] 对于WCF服务端元数据架构体系来说,通过MetadataExporter将服务的终结点导出成MetadataSet(参考< ...

  4. 解决WCF“接收对 http://xxx.svc 的 HTTP 响应时发生错误。这可能是由于服务终结点绑定未使用 HTTP 协议造成的。这还可能是由于服务器中止了 HTTP 请求上下文(可能由于服务关闭)所致"

    最近在工作中新加了一个接口,本地调试的时候,直接抛出“接收对 http://xxx.svc 的 HTTP 响应时发生错误.这可能是由于服务终结点绑定未使用 HTTP 协议造成的.这还可能是由于服务器中 ...

  5. WCF 数据服务 4.5

    .NET Framework 4.5 其他版本 WCF 数据服务(以前称为"ADO.NET Data Services")是 .NET Framework 的一个组件.可以使用此组 ...

  6. WCF中的标准绑定

    使用过WCF的童鞋们都很清楚,绑定是必须的.我将这些绑定总结了下. 一.标准绑定简要说明 1.basicHttpBinding 基于WS-I Basic Profile 1.1 的web服务,所需的. ...

  7. WCF之服务元数据

    服务元数据是用来获得服务的EndPoint的信息,也就是它的ABC. 服务有两种方案可以发布自己的元数据. 一种是基于HTTP-GET协议提供元数据: 一种是元数据交换方式,它往往使用一个专门的终结点 ...

  8. WCF SOA服务应用

    WCF是微软官方推出的一个基于服务的整合框架,它整合了以前的Web Service.MSMQ.Remoting等通信技术,通过灵活的配置,让服务编程更加容易.可扩展.这篇文章主要目的就是带领大家从开发 ...

  9. WCF 配置服务 (02)

    配置服务概述 • 在设计和实现服务协定后,即可配置服务. 在其中可以定义和自定义如何向客户端公开服务,包括指定可以找到服务的地址.服务用于发送和接收消息的传输和消息编码,以及服务需要的安全类型. • ...

随机推荐

  1. window.onload 和 body.onload 相互覆盖的本质

    从根源上讲,window.onload和<body onload="alert('test');"> 所绑定的对象都是window ,body是没有onload事件的, ...

  2. 使用peach工具进行fuzz测试

    本文简要介绍了Fuzz 工具Peach的使用,并通过文件格式 Fuzz举例阐述了 Peach Pit 文件的编写. 本文转自“绿盟科技博客”:http://blog.nsfocus.net/peach ...

  3. 6-19 Count Connected Components(20 分)

    Write a function to count the number of connected components in a given graph. Format of functions: ...

  4. ssh框架中spring整合hibernate的配置文件模板(带详细注释)

    applicationContext.xml的配置文件模板 <?xml version="1.0" encoding="UTF-8"?> <b ...

  5. StringUtils的工具类isBlank与isEmply

    1. public static boolean isEmpty(String str)   判断某字符串是否为空,为空的标准是 str==null 或 str.length()==0   下面是 S ...

  6. 华为OJ:2199 推断输入字符串中的括号匹配

    依据不同的括号有个计数器.在遍历时.当计数器小于0则返回false或者当遍历完后,计数器仍旧不为零,也返回false. import java.util.Scanner; public class b ...

  7. python一条语句分析几个常用函数和概念

    前言 过年也没完全闲着,每天用一点点时间学点东西,本文为大家介绍几个python操作的细节,包含all.any.for in等操作,以及介绍我解决问题的思路. 一.开篇 先从我看到的一个简单的语句开始 ...

  8. UEditor自定义toolbar工具条

    使用ueditor的同学都知道,ueditor里有很多功能,很全面,但有时候我们的编辑器不需要太多的功能,比如前台评论或者留言,就不需要这么多功能了,那我们怎么去定制自己想要的工具呢?官方给出了两个方 ...

  9. centos 安装tomcat 7为服务

    3:安装Tomcat 下载apache-tomcat-7.0.33.tar.gz.解压缩: tar -xzvf apache-tomcat-7.0.33.tar.gz 将解压缩后的文件夹拷贝到/usr ...

  10. 【linux】centos6.5上bugzilla的搭建

    1.安装依赖包 CentOS 6.5默认安装了apche,perl ,需要安装httpd mod_ssl mysql-server mysql php-mysql gcc perl* mod_perl ...