zoukankan      html  css  js  c++  java
  • WCF中tcp简单配置

      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="MyWCFServicebehavior">
              <serviceDebug httpHelpPageEnabled="false"/>
              <serviceMetadata httpGetEnabled="false"/>
              <serviceTimeouts transactionTimeout="00:10:00"/>
              <serviceThrottling maxConcurrentCalls="1000" maxConcurrentInstances="1000" maxConcurrentSessions="1000"/>
            </behavior>
            <!--<behavior name="CalculatorServicebehavior">
              <serviceDebug httpHelpPageEnabled="false"/>
              <serviceMetadata httpGetEnabled="false"/>
              <serviceTimeouts transactionTimeout="00:10:00"/>
              <serviceThrottling maxConcurrentCalls="1000" maxConcurrentInstances="1000" maxConcurrentSessions="1000"/>
            </behavior>-->
          </serviceBehaviors>
        </behaviors>
        <bindings>
          <netTcpBinding>
            <binding name="tcpbinding">
              <security mode="None">
                <transport clientCredentialType="None" protectionLevel="None"/>
              </security>
            </binding>
          </netTcpBinding>
        </bindings>
        <services>
          <service name="MyWCF.Service.MyWCFService" behaviorConfiguration="MyWCFServicebehavior">
            <host>
              <baseAddresses>
                <add baseAddress="net.tcp://localhost:11111/CalculatorService"/>
              </baseAddresses>
            </host>
            <endpoint address="" binding="netTcpBinding" bindingConfiguration="tcpbinding" contract="MyWCF.Interfac.IMyWCF"/>
            <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
          </service>
          <!--<service name="SOA.WCF.Service.MathService" behaviorConfiguration="MathServicebehavior">
            <host>
              <baseAddresses>
                <add baseAddress="net.tcp://localhost:11111/MathService"/>
              </baseAddresses>
            </host>
            <endpoint address="" binding="netTcpBinding" bindingConfiguration="tcpbinding" contract="SOA.WCF.Interface.IMathService"/>
            <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
          </service>-->
        </services>
        <!--<behaviors>
          <serviceBehaviors>
            <behavior name="MathServicebehavior">
              <serviceDebug httpHelpPageEnabled="false"/>
              <serviceMetadata httpGetEnabled="false"/>
              <serviceTimeouts transactionTimeout="00:10:00"/>
              <serviceThrottling maxConcurrentCalls="1000" maxConcurrentInstances="1000" maxConcurrentSessions="1000"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <bindings>
          <basicHttpBinding>
            <binding name="httpbinding"/>
          </basicHttpBinding>
        </bindings>
        <services>
          <service name="SOA.WCF.Service.MathService" behaviorConfiguration="MathServicebehavior">
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:11113/MathService"/>
              </baseAddresses>
            </host>
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="httpbinding" contract="SOA.WCF.Interface.IMathService"/>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>
        </services>-->
    
      </system.serviceModel>

    下面展示代码接口代码:

      [ServiceContract]
        public interface IMyWCF
        {
            [OperationContract]
            void Show();
        }

    展示实现类代码:

     public class MyWCFService : IMyWCF
        {
            public void Show()
            {
                Console.WriteLine("调用显示方式");
            }
        }

    端口激活

       List<ServiceHost> hosts = new List<ServiceHost>()
                {
                    new ServiceHost(typeof(MyWCFService))
                };
                foreach (var host in hosts)
                {
                    host.Opened += (s, e) => Console.WriteLine($"服务端已经打开:{host.GetType().Name}");
                    host.Opening += (s, e) => Console.WriteLine($"服务端正在打开:{host.GetType().Name}");
                    host.Open();
                }

    实体信息:特性类名称[DataContract]。属性特性:DataMember

  • 相关阅读:
    在CentOS 6.7 64位安装PHP的PDO_OCI扩展 Installing PDO_OCI extension on CentOS 6.7 64bit
    Windows下Apache+PHP+MySQL开发环境的搭建(WAMP)
    在Window上用cmd创建.htaccess文件
    Magento 0元订单 支付方式 -- Magento 0 Subtotal Payment Method
    PHP使用OPENSSL RSA加密解密数据
    CentOS编译安装PHP 7.0
    [转] CentOS单独安装Apache Benchmark压力测试工具的办法
    [转] 基于MySQL的秒杀核心设计(减库存部分)-防超卖与高并发
    快速激活JetBrains PhpStorm WebStorm系列产品
    Mac OS的phpize空信息解决办法
  • 原文地址:https://www.cnblogs.com/zxp6/p/10596696.html
Copyright © 2011-2022 走看看