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通信方式

    文章

     
  • 相关阅读:
    XSS漏洞攻击
    String 是值类型还是引用类型
    客户端验证不能代表服务器端验证
    PowerDesigner参照(Reference)笔记
    LazyAllocate(缓分配)与PreAllocate(预分配)
    我在delphi7下调用微软的Web Services的心得.(可以返回数据集)
    C Dungeon Master
    TimeQuest笔记
    XPStyle Button
    对XML文件的CRUD(添加,读取,搜索,修改,删除)的例子
  • 原文地址:https://www.cnblogs.com/llcdbk/p/6374625.html
Copyright © 2011-2022 走看看