Silverlight 动态访问Webservice

            Webservice服务位于Silverlight服务端的ClientBin目录下。

            Silverlight 客户端调用Webservice服务时,首先需要添加服务引用,右键如下图

                                      

            单击Discover按钮,自动查找到Webservice服务。

            在Silverlight后台CS

                using SilverlightChart.EmployeesInfoServiceReference;

                添加动态绑定类

                     public class ServiceUtil
                     {
                         public static EmployeesInfoWebServiceSoapClient GetDynamicClient(string ClientIp)
                          {
                                     BasicHttpBinding binding = new BasicHttpBinding(Application.Current.Host.Source.Scheme.Equals("https",                                  StringComparison.InvariantCultureIgnoreCase) ? BasicHttpSecurityMode.Transport : BasicHttpSecurityMode.None);

                                    binding.MaxReceivedMessageSize = int.MaxValue;

                                    binding.MaxBufferSize = int.MaxValue;

                                    EndpointAddress client = new EndpointAddress(GetHostUrl(ClientIp));

                                    return new EmployeesInfoWebServiceSoapClient(binding, client);
                          }

                        public static EmployeesInfoWebServiceSoapClient GetMyService()   //本地
                         {
                             BasicHttpBinding binding = new BasicHttpBinding(Application.Current.Host.Source.Scheme.Equals("https",  StringComparison.InvariantCultureIgnoreCase) ? BasicHttpSecurityMode.Transport : BasicHttpSecurityMode.None);

                            binding.MaxReceivedMessageSize = int.MaxValue;

                            binding.MaxBufferSize = int.MaxValue;

                             EndpointAddress client = new EndpointAddress(new Uri(Application.Current.Host.Source, "../ClientBin/EmployeesInfoWebService.asmx"));

                             return new EmployeesInfoWebServiceSoapClient(binding, client);
                         }

                      public static string GetHostUrl(string ClientIp)           //远程IP
                         {

                            string str = ClientIp + "/ClientBin/EmployeesInfoWebService.asmx";

                           return str;
                        }
                       }


          添加Silverlight动态调用WebService函数:

                   void ShowChart(string RoomId, string ChartCmd, string SeriesCmd, string roomConnString, DateTime fromDateTime, DateTime toDateTime)
                    {
                           EmployeesInfoWebServiceSoapClient webClient = ServiceUtil.GetDynamicClient(ClientIp);

                           webClient.GetWholeChartInfoCompleted += new EventHandler<GetWholeChartInfoCompletedEventArgs>(webClient_GetWholeChartInfoCompleted);

                           webClient.GetWholeChartInfoAsync(RoomId, ChartCmd, SeriesCmd, roomConnString, fromDateTime, toDateTime);
                     }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值