Вопрос

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);
Это было полезно?

Решение 2

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

Другие советы

Does the actual value that is received have double slashes, or does it just appear in the debugger with double slashes? The debugger will show escape sequences for some characters including \\ for \, but the actual contents of the string will be correct.

If the issue exists outside of the debugger, I would need to see more code to rule out bad input as the source of the problem. Specifically in your send code, what is the structure of this and of ConfSettings? Is the property that is being corrupted set correctly, or did you use a regular string literal instead a verbatim string literal:

string rightVal = "C:\\asdf\\log.log";
string wrongVal = @"C:\\asdf\\log.log";
//string rightVal = @"C:\asdf\log.log";
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top