【发布时间】:2016-11-30 07:32:29
【问题描述】:
我创建了一个由 android 使用的 WCF 服务。它返回一个json字符串,但服务器代码发送的实际字符串数据与访问时不同。
我的网络配置
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="httpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="WcfAndroid.Service1">
<endpoint address=""
behaviorConfiguration="httpBehavior"
binding="webHttpBinding"
contract="WcfAndroid.IService1" />
</service>
</services>
<protocolMapping>
<add binding="webHttpBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
还有我的 WCF 服务接口:
<ServiceContract()>
Public Interface IService1
<OperationContract()> _
<WebGet(UriTemplate:="GetText", BodyStyle:=WebMessageBodyStyle.WrappedRequest, responseformat:=WebMessageFormat.Json, RequestFormat:=WebMessageFormat.Json)> _
Function GetText() As String
End Interface
我正在从服务中返回一个常量字符串进行测试:
Public Function GetText() As String Implements IService1.GetText
'' GetjsonString() returns {"id": 100,"name": "item X","active": true}
Return GetjsonString()
End Function
GetjsonString() 函数返回字符串 {"id": 100,"name": "item X","active": true}
但是当服务被调用时,它会返回:
{\"id\": 100,\"name\":\"item X\",\"active\": true}
我不知道为什么它没有返回实际的字符串?
【问题讨论】:
-
是可以解析的有效数据。它将按预期工作。
-
当我解析字符串时,它会在字符串 \"id\" 中返回额外的斜杠。如输出所示
-
在发送字符串时尝试发送对象。
标签: c# android json vb.net wcf