• WCF使用地址去调用服务端的方法


    前面的章节已经讲过了WCF的代码和SVC页面的分离,这里是分离后,客户端调用代码如下:

                try
                {
                    var myBinding = new BasicHttpBinding();
                    var myEndpoint =
                        new EndpointAddress(
                            new Uri("http://localhost:12857/UserService.svc"));
                    var myChannelFactory = new ChannelFactory<IUserBussiness>(myBinding, myEndpoint);
                    IUserBussiness client = myChannelFactory.CreateChannel();
                    var res = client.DoWork("1111");
                }
                catch (Exception ex)
                {
                    //do something proper here 
                }

    其中,

    BasicHttpBinding使用的是明文,使用的是http基础通信协议,WsHttpBinding使用的是加密的SOPA协议,
    对于
    BasicHttpBinding可以有如下设定:
      public BasicHttpBinding Binging() 
            {
                _cmdServiceBinding = new BasicHttpBinding();
                _cmdServiceBinding.OpenTimeout = new TimeSpan(0, 1, 30);
                _cmdServiceBinding.CloseTimeout = new TimeSpan(0, 1, 30);
                _cmdServiceBinding.SendTimeout = new TimeSpan(1, 30, 0);
                _cmdServiceBinding.ReceiveTimeout = new TimeSpan(0, 3, 0);
                _cmdServiceBinding.MaxBufferSize = int.MaxValue;
                _cmdServiceBinding.MaxBufferPoolSize = int.MaxValue;
                _cmdServiceBinding.MaxReceivedMessageSize = int.MaxValue;
                _cmdServiceBinding.MaxBufferPoolSize = int.MaxValue;
                _cmdServiceBinding.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
                _cmdServiceBinding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
                _cmdServiceBinding.ReaderQuotas.MaxNameTableCharCount = int.MaxValue;
                _cmdServiceBinding.ReaderQuotas.MaxArrayLength = int.MaxValue;
                return _cmdServiceBinding;
            }

    WCF的配置文件不变,但是

    WsHttpBinding如果想要使用的话,需要进行一些设置,不然会爆出
    Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'.。类似这样的错误,WSHTTPBINDING已经专门有写过详情请查看

    编写WsHttpBinding的WCF通信方式

    文章

     
  • 相关阅读:
    Log4j---文件解析以及语法使用
    Sessions 与Cookies详解
    Web三大组件之控制器组件Servlet(转载)
    单向链表和双向链表
    单向队列和环形队列
    稀疏数组
    XML解析器之JAXP与DOM4J
    DTD约束与schema约束的不同
    XML之基础和DTD解析
    数据库----SQL基本查询
  • 原文地址:https://www.cnblogs.com/llcdbk/p/6374625.html
Copyright © 2020-2023  润新知