Silverlight 动态调用 WebService
2009-09-24 15:01
232 查看
1. 配置 IIS 绑定 IP地址
2. 在 SL 中引用 WebService
3. 在需要调用 WebService 的地方写下列代码:
BasicHttpBinding basicBinding = new BasicHttpBinding();
2
3CustomBinding binding = new CustomBinding(basicBinding);
4
5BindingElement binaryElement = new BinaryMessageEncodingBindingElement();
6
7// 删除原来 Elements 集合内的 TextMessageEncodingBindingElement
8
9binding.Elements.Remove(binding.Elements[0]);
10
11// 添加 BinaryMessageEncodingBindingElement
12
13binding.Elements.Insert(0, binaryElement);
14
15// wcf 地址
16
17EndpointAddress endPoint = new EndpointAddress("http://172.168.1.100/DynamicInvokeWCF.Web/DynWCF.svc");
18
19// 创建 wcf 客户端
20
21DynWCFClient client = (DynWCFClient)Activator.CreateInstance(typeof(DynWCFClient), binding, endPoint);
22
23client.DoWorkCompleted += new EventHandler<DoWorkCompletedEventArgs>(client_DoWorkCompleted);
24
25client.DoWorkAsync();
26
27
传统 WebService:
BasicHttpBinding basicBinding = new BasicHttpBinding();
2
3CustomBinding binding = new CustomBinding(basicBinding);
4
5BindingElement binaryElement = new BinaryMessageEncodingBindingElement();
6
7EndpointAddress endPoint = new EndpointAddress("http://172.168.1.100/DynamicInvokeWCF.Web/Asmx.asmx");
8
9AsmxSoapClient client = (AsmxSoapClient)Activator.CreateInstance(typeof(AsmxSoapClient), binding, endPoint);
10
11client.HelloWorldCompleted += new EventHandler<HelloWorldCompletedEventArgs>(client_HelloWorldCompleted);
12
13client.HelloWorldAsync();
14
15
这样就可以动态的调用 webservice 了. 完全不需要 ServiceReferences.ClientConfig 文件了.
2. 在 SL 中引用 WebService
3. 在需要调用 WebService 的地方写下列代码:
BasicHttpBinding basicBinding = new BasicHttpBinding();
2
3CustomBinding binding = new CustomBinding(basicBinding);
4
5BindingElement binaryElement = new BinaryMessageEncodingBindingElement();
6
7// 删除原来 Elements 集合内的 TextMessageEncodingBindingElement
8
9binding.Elements.Remove(binding.Elements[0]);
10
11// 添加 BinaryMessageEncodingBindingElement
12
13binding.Elements.Insert(0, binaryElement);
14
15// wcf 地址
16
17EndpointAddress endPoint = new EndpointAddress("http://172.168.1.100/DynamicInvokeWCF.Web/DynWCF.svc");
18
19// 创建 wcf 客户端
20
21DynWCFClient client = (DynWCFClient)Activator.CreateInstance(typeof(DynWCFClient), binding, endPoint);
22
23client.DoWorkCompleted += new EventHandler<DoWorkCompletedEventArgs>(client_DoWorkCompleted);
24
25client.DoWorkAsync();
26
27
传统 WebService:
BasicHttpBinding basicBinding = new BasicHttpBinding();
2
3CustomBinding binding = new CustomBinding(basicBinding);
4
5BindingElement binaryElement = new BinaryMessageEncodingBindingElement();
6
7EndpointAddress endPoint = new EndpointAddress("http://172.168.1.100/DynamicInvokeWCF.Web/Asmx.asmx");
8
9AsmxSoapClient client = (AsmxSoapClient)Activator.CreateInstance(typeof(AsmxSoapClient), binding, endPoint);
10
11client.HelloWorldCompleted += new EventHandler<HelloWorldCompletedEventArgs>(client_HelloWorldCompleted);
12
13client.HelloWorldAsync();
14
15
这样就可以动态的调用 webservice 了. 完全不需要 ServiceReferences.ClientConfig 文件了.
相关文章推荐
- Silverlight动态调用WEBSERVICE,WCF方法
- Silverlight 动态调用 WebService(转)
- Silverlight动态调用WEBSERVICE,WCF方法
- SilverLight动态调用WebService的方法
- SilverLight动态调用WebService的方法
- Silverlight 动态调用 WebService
- SilverLight2CheckBox动态调用WebService
- Silverlight调用WebService 之 Silverlight动态加载外部XML指定地址的WebService---(动态加载外部XML文件中指定的WebService地址)
- Silverlight 动态调用 WebService
- Silverlight 动态调用 WebService
- WEBService动态调用代码
- 动态调用WebService(C#) (非常实用)
- ArcGIS For Silverlight API 开发中利用WebService调用ArcObjects
- 如何动态调用WebService?
- CXF客户端开发--动态调用webservice
- c#中动态调用webService
- Web Service学习笔记:动态调用WebService
- C# .Net动态调用webService (转载)
- C#不添加引用,动态调用webservice
- .NET动态调用WebService并生成程序集 兼容集成java发布的webserive