2016-12-01 4 views
0

フレームワーク(4.5)を使用してRestful WCFサービスを開発しました。このサービスはAndroidクライアントによって使用されています。Restful Wcf Serviceが正確なjson形式のオブジェクトを返さない

私の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> 

マイインタフェースIService1:

<OperationContract()> _ 
<WebGet(UriTemplate:="/GetEmp/{empid}", ResponseFormat:=WebMessageFormat.Json, RequestFormat:=WebMessageFormat.Json)> _ 
Function GetEmp(ByVal EmpId As String) As DataTable 

<OperationContract()> _ 
<WebGet(UriTemplate:="/GetEmpList/{empid}", ResponseFormat:=WebMessageFormat.Json, RequestFormat:=WebMessageFormat.Json)> _ 
Function GetEmpList(ByVal empid As String) As Employee 

マイサービス:

Public Function GetEmp(ByVal EmpId As String) As DataTable Implements IService1.GetEmp 
    Dim table As New DataTable("mytable") 
    table.Columns.Add("Result", GetType(String)) 
    table.Columns.Add("acc", GetType(String)) 
    table.Columns.Add("name", GetType(String)) 
    table.Columns.Add("paid", GetType(Double)) 
    '' Using EmpId for Fetching data from Database 
    table.Rows.Add("True", EmpId, "Employee1", 5000) 
    table.Rows.Add("True", "2", "Employee2", 2000) 
    Return table 
End Function 
Public Function GetEmpList(empid As String) As Employee Implements IService1.GetEmpList 
    ' Using EmpId for Fetching data from Database 
    ' For Testing Manual Entry is Done 

    Dim EmpKey As String = """2016/Emp""/12" 

    Return New Employee With {.EmpID = empid, .EmpKey = EmpKey, .EmpName = "EmployeeName", .EmpPay = "20000"} 
End Function 

<DataContract()> 
Public Class Employee 
    <DataMember()> 
    Public Property EmpID As String 

    <DataMember()> 
    Public Property EmpKey As String 

    <DataMember()> 
    Public Property EmpName As String 

    <DataMember()> 
    Public Property EmpPay As Decimal 
End Class 

GetEmpListの呼び出し中にすべてのものを除いて、結構ですEmpKey。スラッシュ、バックスラッシュ、ダブルクォートなどの多くの特殊文字が含まれています。上記のコードでは、私は手動で"2016/Emp"/12 のEmpKeyを送信しましたが、正確なキーデータは返されません。

戻り出力は{: "1010"、 "EmpKey": "\" 2016/Empの\ "/ 12"、 "EMPNAME": "EmployeeName"、 "EmpPay" 20000 "のEmpID"}

あります

ここで、EmpKeyは正しくありません。

アンドロイドクライアントに実際のデータを送信するにはどうすればよいですか?私はアンドロイドでHttpURLConnectionを使用しています。

答えて

0

あなたはJsonObjectからEmpKeyのgetValueを取得できます。それは次のように解析できます。

JSONObject jobj = new JSONObject(respons); 
String EmpKey = jobj.getString("EmpKey"); 
関連する問題