Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / March 2006

Tip: Looking for answers? Try searching our database.

Whitespace handling in web services 2.0

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Frobozzj - 10 Mar 2006 17:11 GMT
Whitespace handling in web services has changed between 1.1 and 2.0.  If a
field in a dataset contains only spaces, 1.1 returned an empty string when it
crossed the web services boundary.  Under 2.0, it preserves the spaces.  
While this is correct, it breaks some of our code that was working.  Any easy
work-around?

The following web service/client shows the problem.  Try it in 1.1 and 2.0.

*** Service ***

[WebMethod]
public DataSet GiveMeWhitespace()
{
    DataSet testDS = new DataSet();
    DataTable testTbl = new DataTable("MyTable");
    testDS.Tables.Add(testTbl);
    DataColumn testCol = new DataColumn("Col1", "abc".GetType());
    testCol.AllowDBNull = true;
    testTbl.Columns.Add(testCol);

    DataRow newRow = testTbl.NewRow();
    testTbl.Rows.Add(newRow);
    newRow["Col1"] = null;

    newRow = testTbl.NewRow();
    testTbl.Rows.Add(newRow);
    newRow["Col1"] = "";

    newRow = testTbl.NewRow();
    testTbl.Rows.Add(newRow);
    newRow["Col1"] = " ";

    newRow = testTbl.NewRow();
    testTbl.Rows.Add(newRow);
    newRow["Col1"] = "   ";

    newRow = testTbl.NewRow();
    testTbl.Rows.Add(newRow);
    newRow["Col1"] = "A value";

    newRow = testTbl.NewRow();
    testTbl.Rows.Add(newRow);
    newRow["Col1"] = "Another  value";

    newRow = testTbl.NewRow();
    testTbl.Rows.Add(newRow);
    newRow["Col1"] = "A value  ";

    newRow = testTbl.NewRow();
    testTbl.Rows.Add(newRow);
    newRow["Col1"] = "Another  value  ";

    return testDS;
}

*** Client ***

localhost.Service1 svc = new localhost.Service1();
DataSet testDS = svc.GiveMeWhitespace();       

foreach (DataRow aRow in testDS.Tables[0].Rows)
{
    if (!aRow.IsNull("Col1"))
    {
        TextBox1.Text = TextBox1.Text + "*" + aRow["Col1"].ToString() + "*\n";
    }
    else
    {
        TextBox1.Text = TextBox1.Text + "*{null}*\n";
    }
}
Martin Kulov - 13 Mar 2006 00:21 GMT
> Whitespace handling in web services has changed between 1.1 and 2.0.  If a
> field in a dataset contains only spaces, 1.1 returned an empty string when
[quoted text clipped - 3 lines]
> easy
> work-around?

Hi Frobozzj,

I am not aware of this change, but makes sense to me to return the exact
number of spaces as they were in the original data. You can apply
String.Trim() to your data to get the same behavior as before.

Regards,

Signature

Martin Kulov
http://www.codeattest.com/blogs/martin

MCT
MCSD.NET Early Achiever

Frobozz - 17 Mar 2006 00:25 GMT
I agree that 2.0 is handling it correctly, and I understand the I can do a
Trim().  The problem is that this could affect much of my existing code, and
is quite hard to search for.

I'm scanning my code for == "", == String.Empty, .Compare(""), and the !=
cases as well.  It could be that there is only one place (the one I stumbled
across) that needs to be changed, but it's difficult to tell.

This is one of the biggest "gotcha's" I've run across in upgrading to
VS2005, and very few (if any) people are talking about it on the web.

> I am not aware of this change, but makes sense to me to return the exact
> number of spaces as they were in the original data. You can apply
> String.Trim() to your data to get the same behavior as before.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.