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