• 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

  • 相关阅读:
    Microjs: 超棒的迷你框架和迷你类库搜罗工具
    本周推荐7款CSS3实现的动态特效
    Bootstrap3.1开发的响应式个人简历模板
    10分钟,利用canvas画一个小的loading界面
    四款超棒的jQuery数字化签名插件
    搜索引擎优化网页设计:最佳实践
    推荐超实用的8款jQuery插件
    9款HTML5实现的超酷特效
    想成为程序猿?28个在线学习网站让你变身齐天大圣!
    推荐7款超棒的单页面网站设计模板。关键是!免费!!
  • 原文地址:https://www.cnblogs.com/zxp6/p/10596696.html
Copyright © 2020-2023  润新知