zoukankan      html  css  js  c++  java
  • Silverlight 动态调用 WebService

    1. 配置 IIS 绑定 IP地址

    2. 在 SL 中引用 WebService

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

    image

    WCF :

    WCF 
    BasicHttpBinding basicBinding = new BasicHttpBinding(); 
     
    CustomBinding binding = new CustomBinding(basicBinding); 
     
    BindingElement binaryElement = new BinaryMessageEncodingBindingElement(); 
     
    // 删除原来 Elements 集合内的 TextMessageEncodingBindingElement 
    binding.Elements.Remove(binding.Elements[0]); 
     
    // 添加 BinaryMessageEncodingBindingElement 
     
    binding.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 
    DynWCFClient client = (DynWCFClient)Activator.CreateInstance(typeof(DynWCFClient), binding, endPoint); 
     
    client.DoWorkCompleted += new EventHandler<DoWorkCompletedEventArgs>(client_DoWorkCompleted); 
     
    client.DoWorkAsync(); 
     

    传统 WebService:

    WebService 
    1BasicHttpBinding 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 文件了.

    Powered By D&J (URL:http://www.cnblogs.com/Areas/)
  • 相关阅读:
    【转】Android开发中Handler的使用
    【转】关于微信开发者平台移动应用获取签名解决问题
    AndroidStudio开发工具快捷键
    进程与线程
    【转】Git常用命令
    Java中内存空间的分配及回收
    【转】Github入门教程
    周记
    本周工作内容及感想
    总结
  • 原文地址:https://www.cnblogs.com/Areas/p/2153156.html
Copyright © 2011-2022 走看看