一个奇怪的WEB SERVICE程序

以下的程序出自MSDN
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfsystemwebserviceswebmethodattributeclassbufferresponsetopic.htm
None.gif using  System;
None.gif
using  System.IO;
None.gif
using  System.Collections;
None.gif
using  System.Xml.Serialization;
None.gif
using  System.Web.Services;
None.gif
using  System.Web.Services.Protocols;
None.gif
ExpandedBlockStart.gifContractedBlock.gif
public   class  Streaming  dot.gif {
InBlock.gif
InBlock.gif    [WebMethod(BufferResponse
=false)]
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public TextFile GetTextFile(string filename) dot.gif{
InBlock.gif        
return new TextFile(filename);
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    [WebMethod]
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public void CreateTextFile(TextFile contents) dot.gif{
InBlock.gif        contents.Close();
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
public   class  TextFile  dot.gif {
InBlock.gif    
public string filename;
InBlock.gif    
private TextFileReaderWriter readerWriter;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public TextFile() dot.gif{
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public TextFile(string filename) dot.gif{
InBlock.gif        
this.filename = filename;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    [XmlArrayItem(
"line")]
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public TextFileReaderWriter contents dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gif{
InBlock.gif            readerWriter 
= new TextFileReaderWriter(filename);
InBlock.gif            
return readerWriter;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public void Close() dot.gif{
InBlock.gif        
if (readerWriter != null) readerWriter.Close();
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
public   class  TextFileReaderWriter : IEnumerable  dot.gif {
InBlock.gif
InBlock.gif    
public string Filename;
InBlock.gif    
private StreamWriter writer;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public TextFileReaderWriter() dot.gif{
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public TextFileReaderWriter(string filename) dot.gif{
InBlock.gif        Filename 
= filename;
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public TextFileEnumerator GetEnumerator() dot.gif{
InBlock.gif        StreamReader reader 
= new StreamReader(Filename);
InBlock.gif        
return new TextFileEnumerator(reader);
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    IEnumerator IEnumerable.GetEnumerator() 
dot.gif{
InBlock.gif        
return GetEnumerator();
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public void Add(string line) dot.gif{
InBlock.gif        
if (writer == null)
InBlock.gif            writer 
= new StreamWriter(Filename);
InBlock.gif        writer.WriteLine(line);
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public void Close() dot.gif{
InBlock.gif        
if (writer != null) writer.Close();
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
public   class  TextFileEnumerator : IEnumerator  dot.gif {
InBlock.gif    
private string currentLine;
InBlock.gif    
private StreamReader reader;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public TextFileEnumerator(StreamReader reader) dot.gif{
InBlock.gif        
this.reader = reader;
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public bool MoveNext() dot.gif{
InBlock.gif        currentLine 
= reader.ReadLine();
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (currentLine == nulldot.gif{
InBlock.gif            reader.Close();
InBlock.gif            
return false;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else
InBlock.gif            
return true;
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public void Reset() dot.gif{
InBlock.gif        reader.BaseStream.Position 
= 0;
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public string Current dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gif{
InBlock.gif            
return currentLine;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
object IEnumerator.Current dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gif{
InBlock.gif            
return Current;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

以上是WEB SERVICE的一短代码,在客户端怎么实现这个调用,我觉得有些奇怪,特别是这个方法
None.gif public  TextFile GetTextFile( string  filename) 
ExpandedBlockStart.gifContractedBlock.gif 
dot.gif {
InBlock.gif     
return new TextFile(filename);//只执行了构造函数,
ExpandedBlockEnd.gif
 }

None.gif

返回了一个TextFile对象,但此对象只有一个filename的字段,还完全没有构造好,就返回了,奇怪!!!
还有那个接口,看起来也有点模糊,大家讨论啊!!

转载于:https://www.cnblogs.com/sbj0707/archive/2005/08/20/218928.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值