0
我有一个创建的WCF服务,这是由android使用。它返回一个json字符串,但由服务器代码发送的实际字符串数据与访问时不同。与json的WCF WCF服务
我的web.config
<?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 \ “名称\”:\ “项X \”,\ “活动\”:真正}
我不知道为什么它没有返回实际的字符串?
它是有效数据你可以解析它,它会像预期的那样工作 – Mairaj
当我解析字符串时,它返回字符串\“id \”中的额外斜线,如输出 – Admin
中所示尝试在发送字符串时发送一个对象。 – Mairaj