Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 2nd, 2012, 12:48 PM
Registered User
 
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
 
Old November 2nd, 2012, 03:19 PM
Wrox Author
 
Join Date: Sep 2010
Posts: 175
Thanks: 3
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
 
Old November 18th, 2012, 09:50 PM
Registered User
 
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





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 01: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.