Results 1 to 2 of 2

Thread: NetworkStream Error

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    3

    NetworkStream Error

    I keep getting an error on lines 200, 207: Error CS0246: Cannot find type 'NetworkStream'
    Code:
    Line 1: 
    Line 2:   using System;
    
    Line 3:   using System.Web.Services;
    Line 4:   using System.Xml.Serialization;
    Line 5: using System.Net;
    Line 6: using System.Collections;
    Line 7:   [WebService(Namespace="http://localhost/MyWebServices/")]
    Line 8:   public class FirstService : WebService
    Line 9:   {
    Line 10:       [WebMethod]
    Line 11:       public int Add(int a, int b)
    Line 12:       {
    Line 13:           return a + b;
    Line 14:       }
    Line 15: 
    Line 16:       [WebMethod]
    Line 17:       public String SayHello()
    Line 18:       {
    Line 19:     try
    Line 20:     {
    Line 21:         Smtp smtp = new Smtp();
    Line 22:         smtp.server = "127.0.0.1";
    Line 23:         smtp.from = "yyy@localhost (zzz)";
    Line 24:         smtp.subject = "Hello World";
    Line 25:         smtp.bodyHtml = "<HTML><BODY>Hello World</BODY></HTML>";
    Line 26:         smtp.to.Add("root@localhost");
    Line 27:         smtp.Send();
    Line 28: 	return("success");
    Line 29:     }
    Line 30:     catch
    Line 31:     {
    Line 32: 	return("problem");
    Line 33:     }
    Line 34:       }
    Line 35:   }
    Line 36: public class SmtpException : System.Exception
    Line 37: {
    Line 38:     private string message;
    Line 39:     public SmtpException( string str)
    Line 40:     {
    Line 41:         message = str;
    Line 42:     }
    Line 43:     public string What()
    Line 44:     {
    Line 45:         return message;
    Line 46:     }
    Line 47: };
    Line 48: 
    Line 49: public class Smtp : System.Net.Sockets.TcpClient
    Line 50: {
    Line 51:     public string from = null;
    Line 52:     public ArrayList to;
    Line 53:     public ArrayList cc;
    Line 54:     public ArrayList bcc;
    Line 55:     public string subject = null;
    Line 56:     public string bodyText = null;
    Line 57:     public string bodyHtml = null;
    Line 58:     public string server = null;
    Line 59: public Smtp()
    Line 60: {
    Line 61:     to = new ArrayList();
    Line 62:     cc = new ArrayList();
    Line 63:     bcc = new ArrayList();
    Line 64: }
    Line 65: public void Send()
    Line 66: {
    Line 67:     string message;
    Line 68:     string response;
    Line 69: 
    Line 70:     Connect( server, 25);
    Line 71:     response = Response();
    Line 72:     if (response.Substring( 0, 3) != "220")
    Line 73:     {
    Line 74:         throw new SmtpException( response);
    Line 75:     };
    Line 76: 
    Line 77:     message = "HELO me\r\n";
    Line 78:     Write( message);
    Line 79:     response = Response();
    Line 80:     if (response.Substring( 0, 3) != "250")
    Line 81:     {
    Line 82:         throw new SmtpException( response);
    Line 83:     }
    Line 84: 
    Line 85:     message = "MAIL FROM:<" + from + ">\r\n";
    Line 86:     Write( message);
    Line 87:     response = Response();
    Line 88:     if (response.Substring( 0, 3) != "250")
    Line 89:     {
    Line 90:         throw new SmtpException( response);
    Line 91:     }
    Line 92: 
    Line 93:     foreach ( string address in to )
    Line 94:     {
    Line 95:         try
    Line 96:         {
    Line 97:             message = "RCPT TO:<" + address + ">\r\n";
    Line 98:             Write( message);
    Line 99:             response = Response();
    Line 100:             if (response.Substring( 0, 3) != "250")
    Line 101:             {
    Line 102:                 throw new SmtpException( response);
    Line 103:             }
    Line 104:         }
    Line 105:         catch( SmtpException e)
    Line 106:         {
    Line 107:             System.Console.WriteLine("{ 0}", e.What());
    Line 108:         }
    Line 109:     }
    Line 110: 
    Line 111:     foreach ( string address in cc )
    Line 112:     {
    Line 113:         try
    Line 114:         {
    Line 115:             message = "RCPT TO:<" + address + ">\r\n";
    Line 116:             Write( message);
    Line 117:             response = Response();
    Line 118:             if (response.Substring( 0, 3) != "250")
    Line 119:             {
    Line 120:                 throw new SmtpException( response);
    Line 121:             }
    Line 122:         }
    Line 123:         catch( SmtpException e)
    Line 124:         {
    Line 125:             System.Console.WriteLine("{ 0}", e.What());
    Line 126:         }
    Line 127:     }
    Line 128: 
    Line 129:     foreach ( string address in bcc )
    Line 130:     {
    Line 131:         try
    Line 132:         {
    Line 133:             message = "RCPT TO:<" + address + ">\r\n";
    Line 134:             Write( message);
    Line 135:             response = Response();
    Line 136:             if (response.Substring( 0, 3) != "250")
    Line 137:             {
    Line 138:                 throw new SmtpException( response);
    Line 139:             }
    Line 140:         }
    Line 141:         catch( SmtpException e)
    Line 142:         {
    Line 143:             System.Console.WriteLine("{ 0}", e.What());
    Line 144:         }
    Line 145:     }
    Line 146: 
    Line 147:     message = "DATA\r\n";
    Line 148:     Write( message);
    Line 149:     response = Response();
    Line 150:     if (response.Substring( 0, 3) != "354")
    Line 151:     {
    Line 152:         throw new SmtpException( response);
    Line 153:     }
    Line 154: 
    Line 155:     message = "Subject: " + subject + "\r\n";
    Line 156:     foreach ( string address in to )
    Line 157:     {
    Line 158:         message += "To: " + address + "\r\n";
    Line 159:     }
    Line 160:     foreach ( string address in cc )
    Line 161:     {
    Line 162:         message += "Cc: " + address + "\r\n";
    Line 163:     }
    Line 164: 
    Line 165:     message += "From: " + from + "\r\n";
    Line 166:     if (bodyHtml.Length > 0)
    Line 167:     {
    Line 168:         message += "MIME-Version: 1.0\r\n"
    Line 169:             +" Content-Type: text/ html;\r\n"
    Line 170:             +" charset=\" iso-8859-1\"\r\n";
    Line 171:         message += "\r\n" + bodyHtml;
    Line 172:     }
    Line 173:     else
    Line 174:     {
    Line 175:         message += "\r\n" + bodyText;
    Line 176:     };
    Line 177:     message += "\r\n.\r\n";
    Line 178:     Write( message);
    Line 179:     response = Response();
    Line 180:     if (response.Substring( 0, 3) != "250")
    Line 181:     {
    Line 182:         throw new SmtpException( response);
    Line 183:     }
    Line 184: 
    Line 185:     message = "QUIT\r\n";
    Line 186:     Write( message);
    Line 187:     response = Response();
    Line 188:     if (response.IndexOf(" 221") == -1)
    Line 189:     {
    Line 190:         throw new SmtpException( response);
    Line 191:     }
    Line 192: }
    Line 193: public void Write( string message)
    Line 194: {
    Line 195:     System.Text.ASCIIEncoding en = new System.Text.ASCIIEncoding() ;
    Line 196: 
    Line 197:     byte[] WriteBuffer = new byte[ 1024] ;
    Line 198:     WriteBuffer = en. GetBytes( message) ;
    Line 199: 
    Line 200:     NetworkStream stream = GetStream() ;
    Line 201:     stream. Write( WriteBuffer, 0, WriteBuffer. Length);
    Line 202: }
    Line 203: public string Response()
    Line 204: {
    Line 205:     System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
    Line 206:     byte[] serverbuff = new Byte[ 1024];
    Line 207:     NetworkStream stream = GetStream();
    Line 208:     int count = stream. Read( serverbuff, 0, 1024 );
    Line 209:     if (count == 0)
    Line 210:         return "";
    Line 211: 
    Line 212:     return enc. GetString( serverbuff, 0, count );
    Line 213: }
    Line 214: };

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: NetworkStream Error

    Maybe you're missing this :

    using System.Net.Sockets;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width