zoukankan      html  css  js  c++  java
  • WCF service -- 发布到IIS 上 + 客户端请求

     服务端行为

    1. 创建wcf service

    2. 项目中添加方法Connect() --> 便于客户端访问时判断连接是否成功

    3. 在web.config中添加配置(客户端访问如果有文件, 最好设置最大访问量)

      在system.serviceModel 节点下添加配置

    <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
              <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
            </binding>
          </basicHttpBinding>
          <basicHttpsBinding>
            <binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
              <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
            </binding>
          </basicHttpsBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
              <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <protocolMapping>
          <add binding="basicHttpBinding" scheme="http" />
          <add binding="basicHttpsBinding" scheme="https" />
        </protocolMapping>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
      </system.serviceModel>

    4. 发布到IIS 上(支持http和https)

    客户端行为 (http与https请求)

    1 add service reference

    2. 客户端访问代码(客户端访问如果有文件, 最好设置最大访问量)

    try
                {
                    var url = "http://localhost:9991/Service1.svc";
                    IService1 _service;
                    if (url.StartsWith("https://"))
                    {
                        ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };
                        var basicHttpsBinding = new BasicHttpsBinding()
                        {
                            OpenTimeout = new TimeSpan(0, 5, 0),
                            CloseTimeout = new TimeSpan(0, 5, 0),
                            SendTimeout = new TimeSpan(0, 5, 0),
                            ReceiveTimeout = new TimeSpan(0, 5, 0),
                            MaxReceivedMessageSize = 2147483647,
                            MaxBufferSize = 2147483647,
                            MaxBufferPoolSize = 2147483647
                        };
                        _service = new Service1Client(basicHttpsBinding, new EndpointAddress(url));
                    }
                    else
                    {
                        var basicHttpBinding = new BasicHttpBinding()
                        {
                            OpenTimeout = new TimeSpan(0, 5, 0),
                            CloseTimeout = new TimeSpan(0, 5, 0),
                            SendTimeout = new TimeSpan(0, 5, 0),
                            ReceiveTimeout = new TimeSpan(0, 5, 0),
                            MaxReceivedMessageSize = 2147483647,
                            MaxBufferSize = 2147483647,
                            MaxBufferPoolSize = 2147483647
                        };
                        _service = new Service1Client(basicHttpBinding, new EndpointAddress(url));
                    }
                    var connect = _service.Connect();
                    Console.WriteLine(connect);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                Console.ReadLine();
  • 相关阅读:
    Centos下安装Redis
    BZOJ 4870 [Shoi2017]组合数问题 ——动态规划 矩阵乘法
    BZOJ 4868 [Shoi2017]期末考试 ——三分 枚举
    BZOJ 4584 [Apio2016]赛艇 ——动态规划
    BZOJ 2806 [Ctsc2012]Cheat ——后缀自动机 单调队列优化DP
    BZOJ 2330 [SCOI2011]糖果 ——差分约束系统 SPFA
    Topcoder SRMCards ——贪心
    CTSC 1999 家园 【网络流24题】星际转移
    BZOJ 3489 A simple rmq problem ——KD-Tree
    BZOJ 2733 [HNOI2012]永无乡 ——线段树 并查集
  • 原文地址:https://www.cnblogs.com/zxhome/p/10929585.html
Copyright © 2011-2022 走看看