A backslash character in a string causes the string to evaluate to “nothing” in WCF

I have a WCF application written in VB.NET that takes a common Dictionary(Of String, String) as one of the parameters. When I pass a key / value pair that has a backslash \ as one of the characters in the value, the client automatically changes the entire value to Nothing or in XML it shows this:

 <Value i:nil="true /> 

Is there any special way to avoid backslashes when passing them to a string in a WCF service? As far as I know, the backslash is not a reserved character in XML.

+4
source share
1 answer

What do you call your service? I just tried this script (see the code below) and the server prints the values ​​correctly.

 Public Class StackOverflow_6116861_751090 <ServiceContract()> _ Public Interface ITest <OperationContract()> Sub Process(ByVal dict As Dictionary(Of String, String)) End Interface Public Class Service Implements ITest Public Sub Process(ByVal dict As System.Collections.Generic.Dictionary(Of String, String)) Implements ITest.Process For Each key In dict.Keys Console.WriteLine("{0}: {1}", key, dict(key)) Next End Sub End Class Public Shared Sub Test() Dim baseAddress As String = "http://" + Environment.MachineName + ":8000/Service" Dim host As ServiceHost = New ServiceHost(GetType(Service), New Uri(baseAddress)) host.AddServiceEndpoint(GetType(ITest), New BasicHttpBinding(), "") host.Open() Console.WriteLine("Host opened") Dim factory As ChannelFactory(Of ITest) = New ChannelFactory(Of ITest)(New BasicHttpBinding(), New EndpointAddress(baseAddress)) Dim proxy As ITest = factory.CreateChannel() Dim dict As Dictionary(Of String, String) = New Dictionary(Of String, String) dict.Add("o\ne", "uno") dict.Add("two", "do\s") dict.Add("th\ree", "tr\es") proxy.Process(dict) End Sub End Class 
+1
source

All Articles