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();
  • 相关阅读:
    java-String类
    多线程的细节
    java-多线程的练习----妖,等待唤醒,代码重构,lock到condition
    javascript函数的声明和调用
    表单
    java-多线程的入门_进阶总结
    uboot命令
    u-boot移植 III
    u-boot移植 II
    汇编词典
  • 原文地址:https://www.cnblogs.com/zxhome/p/10929585.html
Copyright © 2011-2022 走看看