服务器端:
<?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. DesignPattern(一)设计模式的六个基本原则

    使用设计模式的根本原因是适应变化,提高代码复用率,使软件更具有可维护性和可扩展性.并且,在进行设计的时候,也需要遵循以下几个原则:单一职责原则.开放封闭原则.里氏代替原则.依赖倒置原则.接口隔离原则. ...

  2. test20181020 B君的第一题

    题意 分析 二次剩余问题. x,y相当于二次方程 \[ x^2-bx+c=0 \mod{p} \] 的两根. 摸意义下的二次方程仍然考虑判别式\(\Delta=b^2-4c\). 它能开根的条件是\( ...

  3. HBase的几个实示例(二)

    1 开发环境 在进行Hbase开发前,需要安装JDK.Hadoop和Hbase,选择一款合适的开发IDE,具体安装方法就不介绍了,我的开发环境: 操作系统:Ubuntu Java版本:jdk1.8 H ...

  4. Maven(4)-利用intellij idea创建maven 多模块项目

    本文通过一个例子来介绍利用maven来构建一个多模块的jave项目.开发工具:intellij idea. 一.项目结构 multi-module-project是主工程,里面包含两个模块(Modul ...

  5. python实现判断一个字符串是否是合法IP地址

    #!usr/bin/env python #encoding:utf-8 ''''' __Author__:沂水寒城 功能:判断一个字符串是否是合法IP地址 ''' import re def jud ...

  6. column count of mysql.proc is wrong. expected 20,found 16. the table is probably corruptd.

    1558 1547 column count of mysql.proc is wrong. expected 20,found 16. the table is probably corruptd. ...

  7. AngularJS资源大集锦

    AngularJS最近貌似很火,前段时间,CSDN的编辑专访了AngularJS创始人Misko Hevery.这不,Tuts+网站编辑Rey Bango应广大读者需要,把各种极好的AngularJS ...

  8. opensuse下配置IP、DNS、GATEWAY

    本人物理主机IP描述 IPv4 地址 . . . . . . . . . . . . : 192.168.1.101(首选)子网掩码  . . . . . . . . . . . . : 255.25 ...

  9. linux Posix 信号量 三 (经典例子)

    本文将阐述一下信号量的作用及经典例子,当中包括“<越狱>寄信”,“家庭吃水果”,“五子棋”,“接力赛跑”,“读者写者”,“四方恋爱”等 首先,讲 semWait操作(P操作)和semSig ...

  10. Python中表达式和语句及for、while循环练习

    Python中表达式和语句及for.while循环练习 1)表达式 常用的表达式操作符: x + y, x - y x * y, x / y, x // y, x % y 逻辑运算: x or y, ...