加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

动态调用 WebService

发布时间:2020-12-17 01:26:26 所属栏目:安全 来源:网络整理
导读:动态调用 WebService 1. 配置 IIS 绑定 IP地址 2. 在 SL 中引用 WebService 3. 在需要调用 WebService 的地方写下列代码: WCF : ? ? WCF ?1 BasicHttpBinding?basicBinding? = ? new ?BasicHttpBinding(); ?2 ?3 CustomBinding?binding? = ? new ?CustomBind

动态调用 WebService

1. 配置 IIS 绑定 IP地址

2. 在 SL 中引用 WebService

3. 在需要调用 WebService 的地方写下列代码:

image

WCF :

?

?


?1

BasicHttpBinding?basicBinding?=?new?BasicHttpBinding();
?2


?3

CustomBinding?binding?
=?new?CustomBinding(basicBinding);
?4


?5

BindingElement?binaryElement?
=?new?BinaryMessageEncodingBindingElement();?
?6


?7

//?删除原来?Elements?集合内的?TextMessageEncodingBindingElement
?8


?9

binding.Elements.Remove(binding.Elements[
0]);?
10


11

//?添加?BinaryMessageEncodingBindingElement
12


13

binding.Elements.Insert(
0,?binaryElement);
14


15

//?wcf?地址
16


17

EndpointAddress?endPoint?
=?new?EndpointAddress("http:");
//172.168.1.100/DynamicInvokeWCF.Web/DynWCF.svc18


19

//?创建?wcf?客户端
20


21

DynWCFClient?client?
=?(DynWCFClient)Activator.CreateInstance(typeof(DynWCFClient),?binding,?endPoint);
22


23

client.DoWorkCompleted?
+=?new?EventHandler<DoWorkCompletedEventArgs>(client_DoWorkCompleted);
24


25

client.DoWorkAsync();
26


27

?

?

传统 WebService:


?1

BasicHttpBinding?basicBinding?=?new?BasicHttpBinding();
?2


?3

CustomBinding?binding?
=?new?CustomBinding(basicBinding);
?4


?5

BindingElement?binaryElement?
=?new?BinaryMessageEncodingBindingElement();?
?6


?7

EndpointAddress?endPoint?
=?new?EndpointAddress("http:");//172.168.1.100/DynamicInvokeWCF.Web/Asmx.asmx
?8


?9

AsmxSoapClient?client?
=?(AsmxSoapClient)Activator.CreateInstance(typeof(AsmxSoapClient),?endPoint);
10


11

client.HelloWorldCompleted?
+=?new?EventHandler<HelloWorldCompletedEventArgs>(client_HelloWorldCompleted);
12


13

client.HelloWorldAsync();?
14


15

?

这样就可以动态的调用 webservice 了.? 完全不需要 ServiceReferences.ClientConfig 文件了.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读