Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
i have the folowing model

C#
public class Store
{
   public string StoreName {get; set;}
   public string Price {get;set;}
   public string PriceSeparator {get; set;}
   public string Currency {get;set;}
}


C#
var storeModel = new Store();


storeModel gets populated from a wpf window with textboxes;

and i have the following call

C#
WcfService serviceClient = new WcfServiceClient();
serviceClient.SaveStoreModel(storeModel);


at the moment of the call i have the
C#
storeModel.PriceSeparator = " ";


when debugging the Wcf Service i have
C#
storeModel.PriceSeparator = "";


How set the model to not trim whitespaces between calls, or what should i do to achieve this.

Thanks very much!

What I have tried:

This is what i've tried
C#
public class Store
{
   public string StoreName {get; set;}
   public string Price {get;set;}
   [Required(AllowEmptyStrings = true)
   public string PriceSeparator {get; set;}
   public string Currency {get;set;}
}
Posted
Updated 13-May-20 3:26am
Comments
Rob Philpott 3-Mar-16 10:15am    
Ok, filtering what you say, I presume the WPF is irrelevant, the whitespace is lost during the WCF call?

Which binding are you using?
[no name] 3-Mar-16 10:23am    
You're assumuing is correctly when the webservice between the call of the WCF service the whitespace is lost. what type of binding are you talking about in WPF i don't use any biding.

I've scrapped the web and i found this https://social.msdn.microsoft.com/Forums/vstudio/en-US/58101c0e-5c9b-43fd-8acb-becfd0d3e486/strings-stripped-of-leading-whitespace-when-using-mtom-message-encoding?forum=wcf apparently it is a bug. i'm gonna try an workaround of this
F-ES Sitecore 3-Mar-16 12:30pm    
You could send a token instead like; "[space]" and in your service method do a string.Replace and convert [space] back to " "
Wonde Tadesse 3-Mar-16 20:31pm    
Why you want to use MTOM. Using basic http binding sufficient for this case.
Afzaal Ahmad Zeeshan 3-Mar-16 14:06pm    
Otherwise, send the character value for a space.

This issue was introduce back with .NET 4.5, and there still hasn't been a clear fix; However you can try to workaround this by putting special whitespace characters.

For example, try;
C#
storeModel.PriceSeperator = "\u2007";


Or alternatively, as suggested by placing some kind of keyword identifier to detect if it's a space and apply the space before output.
 
Share this answer
 
You could use "\t", I think, to give you a tab character. That might make the spacing more clear.
C#
storeModel.PriceSeparator = @"\t";
 
Share this answer
 
Sorry,I don't know what's the significance for you

I don't think the WCF will filter Spaces

If really as you say
eg:
storeModel.PriceSeparator =storeModel.PriceSeparator .Replace(""," ");
 
Share this answer
 
v2
I temporarily solved it in controller GET method this way:
C#
parameterName = Request.Query["parameterName"].FirstOrDefault() as string;
if (parameterName == string.Empty)
    parameterName = null;
 
Share this answer
 
v2
Comments
Richard Deeming 13-May-20 12:49pm    
That doesn't seem to have any connection to the question, which has already been solved.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900