Search code examples
c#jsonwcfslash

WCF Web JSON request double slash


I have WCF Service with method which sends path like : "C:\asdf\log.log".

Client gets "C:\\asdf\\log.log"

Where is problem and how to solve is?

Send code

MemoryStream stream1 = new MemoryStream();
DataContractJsonSerializer ser =
    new DataContractJsonSerializer(typeof(ConfSettings));
ser.WriteObject(stream1, this);
stream1.Position = 0;
StreamReader sr = new StreamReader(stream1);
string tmp = sr.ReadToEnd();
return (tmp);

Resieve code

Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
string result = responseFromServer;
string tmp = result
byte[] bytes = new byte[tmp.Length * sizeof(char)];
System.Buffer.BlockCopy(tmp.ToCharArray(), 0, bytes, 0, bytes.Length);
MemoryStream memStream = new MemoryStream(bytes, 2, bytes.Length-4);
DataContractJsonSerializer ser =
    new DataContractJsonSerializer(typeof(ConfSettings));
conf = (ConfSettings)ser.ReadObject(memStream);

Solution

  • Problem was in DataContractJsonSerializer. I replace it with JavaScriptSerializer and now this works great! Thanks for the answers!