﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-我生命中的一段日子-随笔分类-Web 开发</title><link>http://www.cppblog.com/guohan/category/575.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 23 May 2008 11:29:24 GMT</lastBuildDate><pubDate>Fri, 23 May 2008 11:29:24 GMT</pubDate><ttl>60</ttl><item><title>在web service中得到客户端IP</title><link>http://www.cppblog.com/guohan/archive/2006/01/09/2501.html</link><dc:creator>郭汉</dc:creator><author>郭汉</author><pubDate>Mon, 09 Jan 2006 01:49:00 GMT</pubDate><guid>http://www.cppblog.com/guohan/archive/2006/01/09/2501.html</guid><wfw:comment>http://www.cppblog.com/guohan/comments/2501.html</wfw:comment><comments>http://www.cppblog.com/guohan/archive/2006/01/09/2501.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guohan/comments/commentRss/2501.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guohan/services/trackbacks/2501.html</trackback:ping><description><![CDATA[<FONT face=Verdana>&nbsp;通过代理，</FONT><A class=bluekey href="http://www.yesky.com/key/2892/187892.html" target=_blank><FONT face=Verdana>获取</FONT></A><FONT face=Verdana>真实的ip</FONT>
<P><FONT style="BACKGROUND-COLOR: #dddddd"><FONT face=Verdana>if(Context.Request.ServerVariables["HTTP_</FONT><A class=bluekey href="http://www.yesky.com/key/496/496.html" target=_blank><FONT face=Verdana>VIA</FONT></A><FONT face=Verdana>"]!=null)<BR>{ <BR>ip=Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].</FONT><A class=bluekey href="http://www.yesky.com/key/2245/207245.html" target=_blank><FONT face=Verdana>ToString</FONT></A><FONT face=Verdana>(); <BR>}<BR>else<BR>{ <BR>ip=Context.Request.ServerVariables["</FONT><A class=bluekey href="http://www.yesky.com/key/1987/506987.html" target=_blank><FONT face=Verdana>REMOTE</FONT></A><FONT face=Verdana>_ADDR"].ToString(); <BR>}</FONT></FONT></P></A><img src ="http://www.cppblog.com/guohan/aggbug/2501.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guohan/" target="_blank">郭汉</a> 2006-01-09 09:49 <a href="http://www.cppblog.com/guohan/archive/2006/01/09/2501.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Web Service 异步调用</title><link>http://www.cppblog.com/guohan/archive/2006/01/09/2500.html</link><dc:creator>郭汉</dc:creator><author>郭汉</author><pubDate>Mon, 09 Jan 2006 01:32:00 GMT</pubDate><guid>http://www.cppblog.com/guohan/archive/2006/01/09/2500.html</guid><wfw:comment>http://www.cppblog.com/guohan/comments/2500.html</wfw:comment><comments>http://www.cppblog.com/guohan/archive/2006/01/09/2500.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guohan/comments/commentRss/2500.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guohan/services/trackbacks/2500.html</trackback:ping><description><![CDATA[<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 最近在完成一些与Socket 通讯相关的东西，希望能够将Socket 通讯的结果以Web Service 的形式发布出来，但是由于Socket 通讯是异步的，所以想当然的认为Web Service 应该异步返回，于是去搜索了一些资料。收集回来才发现有误。但是却是很好的例子代码，现摘录如下：<BR><BR>在.net1.x中，异步WebService异步调用的一般方式为调用方法XX对应的BeginXX方法来完成，其过程类似于异步委托的使用。</P>
<P>　　体验.NET 2.0的优雅之异步Web服务调用<BR><BR><BR>在.net2.0中(准确的说是vs.net 2005中)，异步WebService异步调用的方式的例子：</P>
<P class=code>void DoSomethingTest()<BR>{<BR>　localhost.Service service = new WindowsApp.localhost.Service();<BR><BR>　service.HelloWorldCompleted += new WindowsApp.localhost.HelloWorldCompletedEventHandler(service_HelloWorldCompleted);<BR>　// do Asyn calling here<BR>　service.HelloWorldAsync();<BR>}<BR><BR>void service_HelloWorldCompleted(object sender, WindowsApp.localhost.HelloWorldCompletedEventArgs e)<BR>{<BR>　if (e.Error == null)<BR>　{<BR>　　MessageBox.Show(e.Result);<BR>　}<BR>　else<BR>　{<BR>　　MessageBox.Show(e.Error.Message);<BR>　}<BR>}</P>
<P>　　服务器端代码</P>
<P class=code>[WebService(Namespace = "http://tempuri.org/")]<BR>[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]<BR>public class Service : System.Web.Services.WebService<BR>{<BR>　public Service () {}<BR><BR>　[WebMethod]<BR>　public string HelloWorld() {<BR>　　return "Hello World";<BR>　}<BR>}</P>
<P>　　很简单，没有了AsyncCallback、IAsyncResult 这两个烦人的东西，调用的代码变得简洁、优雅了，而且可以从e.Result得到强类型的返回值（上例为"Hello World"）。但是，有兴趣的话，可以看看vs.net2005生成的Referance.cs文件，那可比2003中的复杂很多。其中可以看到System.ComponentModel.AsyncCompletedEventArgs 、 System.Threading.SendOrPostCallback（delegate）这两个在 .net 1.x 中没有的“怪物”，估计用到的地方还不止WebService客户端。</P><img src ="http://www.cppblog.com/guohan/aggbug/2500.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guohan/" target="_blank">郭汉</a> 2006-01-09 09:32 <a href="http://www.cppblog.com/guohan/archive/2006/01/09/2500.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>