zoukankan      html  css  js  c++  java
  • 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通信方式

    文章

     
  • 相关阅读:
    PL/SQL Developer使用技巧、快捷键(转发)
    Java 获取随机日期
    jsonArray和Java List对象互转,日期处理
    ExtJs grid单选,多选
    ExtJs 下拉单联动,次级下拉框查询模式
    ExtJs 日期相加,Grid表格列可编辑
    转:Java阳历转农历
    转:Java 计算2个时间相差多少年,多少个月,多少天的几种方式
    钥匙计数之一
    LianLianKan
  • 原文地址:https://www.cnblogs.com/llcdbk/p/6374625.html
Copyright © 2011-2022 走看看