zoukankan      html  css  js  c++  java
  • .NET2.0环境下客户端使用WebService的一点认识.

    Solo Spirit 那个天气预报是调用网上一个免费的WebService的.
    客户端调用WebService的使用方法两种:
    (一),在引用里添加Web引用,然后就像使用普通类一样使用.
    (二).在.net命令行输入
    wsdl   http//url/xxx.asmx   /language:cs   /out:xxx.cs   /protocol:httpGet
    可生成HttpGet的代理类.

    一.用第一种的方法时:
    VS2005在Web和WinForm工程,同样添加Web引用.生成的文件不大相同
    Winform生成的Reference.map.Service.disco Service.wsdl三个文件.
    WebForm生成.webservice.discomap,Service.disco Service.wsdl 三个文件
    在.net1.x中,异步WebService异步调用的一般方式为调用方法XX对应的BeginXX方法来完成
    在..net2.0中.用(一)方法在WinForm里无法找到BeginXX方法.但WebForm里依然有
    .net2.0中异步使用要优雅的多,没有了AsyncCallback、IAsyncResult
    见:http://www.cnblogs.com/QuitGame/archive/2005/11/13/275066.html

    void DoSomethingTest() 
            

                localhost.Service service 
    = new WindowsApp.localhost.Service(); 
     
                service.HelloWorldCompleted 
    += new WindowsApp.localhost.HelloWorldCompletedEventHandler(service_HelloWorldCompleted); 
                
    // do Asyn calling here 
                service.HelloWorldAsync(); 
            }
     
     
            
    void service_HelloWorldCompleted(object sender, WindowsApp.localhost.HelloWorldCompletedEventArgs e) 
            

                
    if (e.Error == null
                

                    MessageBox.Show(e.Result); 
                }
     
                
    else 
                

                    MessageBox.Show(e.Error.Message); 
                }
     
            }
     


    二.用代理类生成的类的方法里将包含BeginXX,EndXX类型的方法

  • 相关阅读:
    python025 Python3 正则表达式
    python024 Python3 实例
    python023 Python3 标准库概览
    python022 Python3 面向对象
    python021 Python3 错误和异常
    列表和元组的元素不可被修改,但列表和元组的元素的元素可以被修改
    织梦标签
    自动添加QQ
    php把时间存入数据库为年月日时分秒类型
    PHP后台批量删除数据
  • 原文地址:https://www.cnblogs.com/solo/p/678909.html
Copyright © 2011-2022 走看看