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

  • 相关阅读:
    WebForms UnobtrusiveValidationMode 须要“jquery”ScriptResourceMapping。
    用R进行微博分析的初步尝试
    使用Docker部署Gitlab
    怎样托管你的项目到github上具体教程
    Android Api Demos登顶之路(四十五)Loader--&gt;Cursor
    【C语言】推断一个数是否为2的n次方
    Akka并发编程——第五节:Actor模型(四)
    POJ2773 Happy 2006【容斥原理】
    作用域与生命周期
    C# string
  • 原文地址:https://www.cnblogs.com/zxp6/p/10596696.html
Copyright © 2011-2022 走看看