﻿<?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++博客-我生命中的一段日子</title><link>http://www.cppblog.com/guohan/</link><description /><language>zh-cn</language><lastBuildDate>Thu, 09 Apr 2026 01:04:49 GMT</lastBuildDate><pubDate>Thu, 09 Apr 2026 01:04:49 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><item><title>第一个问题  explicit 关键字</title><link>http://www.cppblog.com/guohan/archive/2005/11/28/1360.html</link><dc:creator>郭汉</dc:creator><author>郭汉</author><pubDate>Mon, 28 Nov 2005 04:08:00 GMT</pubDate><guid>http://www.cppblog.com/guohan/archive/2005/11/28/1360.html</guid><wfw:comment>http://www.cppblog.com/guohan/comments/1360.html</wfw:comment><comments>http://www.cppblog.com/guohan/archive/2005/11/28/1360.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guohan/comments/commentRss/1360.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guohan/services/trackbacks/1360.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在Primer 的第27页发现其的源代码使用了一个 Explicit 关键字&nbsp;，以前从未用到。不解其意。得到资料如下：<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 主旨就是申明在使用单一操作符时，避免隐式转换。强行要求使用显示转换<BR><BR><BR><BR><BR><BR>----------------------------------------------------------------------------------------------------------<BR><BR>带单一参数的构造函数在缺省情况下隐含一个转换操作符，请看下面的代码：<BR><BR>class C {<BR>int i;<BR>//...<BR>public:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C(int i);//constructor and implicit conversion operator<BR>//as well<BR>};<BR><BR>void f() {<BR><BR>C c(0);<BR><BR>c = 5; //将 5 隐式转换为 C 对象，然后赋值<BR><BR>}<BR><BR>编译器重新编辑上述例子代码，如下： <BR><BR>//////////////////////////////////////////////////////////////////////////////////////////<BR>//"c=5;" 被编译器转换成下面这个样子：<BR>/////////////////////////////////////////////////////////////////////////////////////////<BR><BR>C temp(5);// 实例化一个临时对象,<BR>c = temp; // 用 = 赋值<BR>temp.C::~C(); // temp 的析构函数被激活<BR><BR>在很多情况下，这个转换是有意的，并且是正当的。但有时我们不希望进行这种自动的转换，例如：<BR><BR>class String {<BR>int size;<BR>char *p;<BR>//..<BR>public:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String (int sz); //这里不希望进行隐式转换操作<BR>};<BR>void f ()<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;String s(10);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;// 下面是一个程序员的编码；发生一个意想不到的转换：<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;s = 100; // 糟糕，100 被转换为一个 String，然后被赋值给 s<BR>} <BR><BR>为了避免这样的隐式转换，应该象下面这样显式声明该带单一参数的构造函数：<BR><BR>class String {<BR>int size;<BR>char *p;<BR>//..<BR>public:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 不要隐式转换<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; explicit String (int sz); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String (const char *s, int size n = 0); // 隐式转换<BR>};<BR><BR>void f ()<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;String s(10);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;s = 100; // 现在编译时出错；需要显式转换：<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;s = String(100); // 好；显式转换<BR>&nbsp;&nbsp;&nbsp;&nbsp;s = "st";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// 好；此时允许隐式转换<BR>}<BR><img src ="http://www.cppblog.com/guohan/aggbug/1360.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guohan/" target="_blank">郭汉</a> 2005-11-28 12:08 <a href="http://www.cppblog.com/guohan/archive/2005/11/28/1360.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>开始</title><link>http://www.cppblog.com/guohan/archive/2005/11/28/1356.html</link><dc:creator>郭汉</dc:creator><author>郭汉</author><pubDate>Mon, 28 Nov 2005 03:27:00 GMT</pubDate><guid>http://www.cppblog.com/guohan/archive/2005/11/28/1356.html</guid><wfw:comment>http://www.cppblog.com/guohan/comments/1356.html</wfw:comment><comments>http://www.cppblog.com/guohan/archive/2005/11/28/1356.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/guohan/comments/commentRss/1356.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guohan/services/trackbacks/1356.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp; 今日，我开始了我的C++学习之路。使用的书是&nbsp; C++&nbsp; Primer 和&nbsp; STL。计划在2个月完成，希望这个Blog 能够见证我的学习之路。 <img src ="http://www.cppblog.com/guohan/aggbug/1356.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guohan/" target="_blank">郭汉</a> 2005-11-28 11:27 <a href="http://www.cppblog.com/guohan/archive/2005/11/28/1356.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>