.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类型的方法

posted on 2007-03-18 14:45  Haozes  阅读(1087)  评论(2编辑  收藏  举报