Vb.net 字符串中的反斜杠字符导致字符串的计算结果为";“什么都没有”;在WCF中

Vb.net 字符串中的反斜杠字符导致字符串的计算结果为";“什么都没有”;在WCF中,vb.net,wcf,Vb.net,Wcf,我有一个用VB.NET编写的WCF应用程序,它将一个通用的字典(字符串,字符串)作为参数之一。 当我传入一个键/值对,该键/值对的值中有一个反斜杠\作为字符之一时,客户端会自动将整个值更改为Nothing,或在XML中显示以下内容: <Value i:nil="true /> 您如何呼叫您的服务?我刚刚尝试了这个场景(参见下面的代码),服务器正确地打印了这些值 Public Class StackOverflow_6116861_751090 <ServiceCont

我有一个用VB.NET编写的WCF应用程序,它将一个通用的
字典(字符串,字符串)
作为参数之一。 当我传入一个键/值对,该键/值对的值中有一个反斜杠
\
作为字符之一时,客户端会自动将整个值更改为
Nothing
,或在XML中显示以下内容:

<Value i:nil="true />

您如何呼叫您的服务?我刚刚尝试了这个场景(参见下面的代码),服务器正确地打印了这些值

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
公共类堆栈溢出\u 611661\u 751090
_
公共接口测试
子进程(ByVal dict作为字典(字符串、字符串))
端接口
公务舱服务
实施ITest
公共子进程(ByVal dict作为System.Collections.Generic.Dictionary(字符串,字符串))实现ITest.Process
对于dict.Keys中的每个键
Console.WriteLine(“{0}:{1}”,key,dict(key))
下一个
端接头
末级
公共共享子测试()
Dim baseAddress为String=“http://”+Environment.MachineName+“:8000/服务”
作为ServiceHost的Dim主机=新ServiceHost(GetType(服务),新Uri(基地址))
host.AddServiceEndpoint(GetType(ITest),新的BasicHttpBinding(),“”)
host.Open()
Console.WriteLine(“主机已打开”)
Dim工厂作为ChannelFactory(ITest的)=新的ChannelFactory(ITest的)(新的BasicHttpBinding(),新的EndpointAddress(baseAddress))
Dim代理作为ITest=factory.CreateChannel()
Dim dict As Dictionary(字符串的,字符串的)=新字典(字符串的,字符串的)
dict.Add(“o\ne”、“uno”)
dict.Add(“两个”、“做”)
dict.Add(“th\ree”,“tr\es”)
代理进程(dict)
端接头
末级

代码块显示前需要一个空行。顺便说一下,欢迎使用堆栈溢出。我找到了问题的根源。我是从WCF测试客户端调用该服务的,它不会像VB调用该服务时那样自动转义反斜杠字符。它在程序中运行良好。