1 ///<summary>
2 /// 得到WebService对象
3 /// 以后实例化WebService代理时请用var serviceClient = Utility.GetDesignerServiceInstance();的形式,
4 /// 不要再用默认的 var serviceClient = new WSDesignerSoapClient();
5 /// 后一种形式会报错,因为我们删除了ServiceReferences.ClientConfig文件
6 ///</summary>
7 ///<returns></returns>
8 public static WSDesignerSoapClient GetDesignerServiceInstance()
9 {
10 var basicBinding = new BasicHttpBinding() { MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue, Name = "WSDesignerSoap" };
11 basicBinding.Security.Mode = BasicHttpSecurityMode.None;
12 var endPoint = new EndpointAddress(getHostUrl() + "/WebService.asmx");
13 var ctor =
14 typeof (WSDesignerSoapClient).GetConstructor(new Type[] {typeof (Binding), typeof (EndpointAddress)});
15 return (WSDesignerSoapClient) ctor.Invoke(new object[] {basicBinding, endPoint});
16 }
17
18
19 ///<summary>
20 /// 得到当前所在网站的根目录,如Http://localhost/flow
21 /// 注意站点名字必须是Flow,否则会报错。
22 ///</summary>
23 ///<returns></returns>
24 private static string getHostUrl()
25 {
26 var location = (HtmlPage.Window.GetProperty("location")) as ScriptObject;
27 var hrefObject = location.GetProperty("href");
28 string url = hrefObject.ToString().Substring(0, hrefObject.ToString().IndexOf("Flow/") + 5);
29 return url;
30 }