Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional C# 4.0 and .NET 4
This is the forum to discuss the Wrox book Professional C# 4.0 and .NET 4 by Christian Nagel, Bill Evjen, Jay Glynn, Karli Watson, Morgan Skinner; ISBN: 9780470502259
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional C# 4.0 and .NET 4 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 2nd, 2012, 01:48 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Web Services Chapter 25

When I tried to execute the sample in Chapter 25, I could not do completely.

Being a beginner I could n't locate the errors.

Below are the errors I am getting from the following code.

A) ( QuoteServer/QuoteServer.cs )
-----------------------------------------------------------------
protected void ListenerThread()
{
try
{
IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
listener = new TcpListener(ipAddress, port);
listener.Start();
while (true)
{
Socket clientSocket = listener.AcceptSocket();
string message = GetRandomQuoteOfTheDay();
UnicodeEncoding encoder = new UnicodeEncoding();
byte[] buffer = encoder.GetBytes(message);
clientSocket.Send(buffer, buffer.Length, 0);
clientSocket.Close();
}
}
---------------------------------------------------------------------
1) listener object returns NULL.
2) listener.AcceptSocket(); returns nothing being listener is NULL
----------------------------------------------------------------------
B) QuoteClient/MainWindow.xaml.cs
----------------------------------------------------------
protected void OnGetQuote(object sender, RoutedEventArgs e)
{
const int bufferSize = 1024;
Cursor currentCursor = this.Cursor;
this.Cursor = Cursors.Wait;
string serverName = Properties.Settings.Default.ServerName;
int port = Properties.Settings.Default.PortNumber;
var client = new TcpClient();
NetworkStream stream = null;
try
{
client.Connect(serverName, port);
stream = client.GetStream();
byte[] buffer = new byte[bufferSize];
int received = stream.Read(buffer, 0, bufferSize);
if (received <= 0)
{
return;
}
textQuote.Text = Encoding.Unicode.GetString(buffer).Trim('\0');
}
-------------------------------------------------------------
1) Client.Connect - doesn't connect any
2) Stream also NULL
3) received is 0
------------------------------------------------------------------
Not sure about the error.

Please let me know if any order I need to follow to execute this service.

For example , I need to run the service, run the service and client etc.

Details about Local host, port number etc.

Try to suggest how to run the whole program.

Thanks
Srikanth V
  #2 (permalink)  
Old November 2nd, 2012, 04:19 PM
Wrox Author
Points: 1,151, Level: 13
Points: 1,151, Level: 13 Points: 1,151, Level: 13 Points: 1,151, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2010
Location: Austria
Posts: 171
Thanks: 2
Thanked 53 Times in 53 Posts
Default

Quote:
Originally Posted by vensrikanth View Post
---------------------------------------------------------------------
1) listener object returns NULL.
2) listener.AcceptSocket(); returns nothing being listener is NULL
----------------------------------------------------------------------
How did you verify that listener is null?
If listener would be null, calling AcceptSocket() would throw a NullReferenceException.
What do you mean with AcceptSocket() returns nothing? Do you mean this method blocks and the program stays there? This should be the case until a client connects.

Quote:
Originally Posted by vensrikanth View Post

-------------------------------------------------------------
1) Client.Connect - doesn't connect any
2) Stream also NULL
3) received is 0
------------------------------------------------------------------
What happen's with "doesn't connect any"? Did you change the server name to your machine?
If the stream is null, stream.Read() would throw a NullReferenceException, and not assign a 0 value to received.

Can you please supply more information on the errors you see?
__________________
Christian
CN innovation
Visit my blog at: csharp.christiannagel.com
Follow me on twitter: @christiannagel
  #3 (permalink)  
Old November 18th, 2012, 09:50 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

the Port and the ServerName is null? you may confirm the setting proper and check it work,the client and customer will use the same port and ServerName .I think you problem will it cause
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 19 Web Services sef BOOK: Beginning Visual C# 2010 3 February 14th, 2012 09:11 AM
Chapter 5 - Web Services Sample mjk12345 BOOK: Professional SharePoint 2007 Development ISBN: 978-0-470-11756-9 2 July 8th, 2008 02:53 PM
Chapter 6 : Web Services and Ajax 2mk BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 February 11th, 2008 04:21 AM
Web Services SOAP Example (Chapter 26) pagates BOOK: Professional C#, 2nd and 3rd Editions 0 February 17th, 2005 03:16 PM



All times are GMT -4. The time now is 03:39 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.