C# WCF服务未返回Json中的完整对象

C# WCF服务未返回Json中的完整对象,c#,asp.net,json,wcf,C#,Asp.net,Json,Wcf,在我的svc类中有上面的方法。但这不能完全用Json发送数据。我得到下面的结果 [OperationContract] public FareDataModel GetFareAndDistanceJson(string source, string destination, string country, string city) { return FareManager.GetFare(source, destination, country, city);

在我的svc类中有上面的方法。但这不能完全用Json发送数据。我得到下面的结果

[OperationContract]
    public FareDataModel GetFareAndDistanceJson(string source, string destination, string country, string city)
    {
       return  FareManager.GetFare(source, destination, country, city);


    }
但是当我以字符串的形式返回它时,我得到的数据是字符串形式的,我真的想得到json。 这是我的FareDataModel对象

 {
"d": {
    "__type": "FareDataModel:#MeterupAutoTaxiWebService",
    "Fares": [
        {
            "__type": "VehicleFare:#MeterupAutoTaxiWebService"
        }
    ]
}
}
我得到以下结果

[OperationContract]
    public string GetFareAndDistanceJson(string source, string destination, string country, string city)
    {

       return new JavaScriptSerializer().Serialize(FareManager.GetFare(source, destination, country, city));

    }
我真的需要一个真正的json响应

这是我的班级

    {
    "d": "{\"SourceAddress\":\"Majestic, Bangalore, Karnataka, India\",\"DestinationAddress\":\"Marathahalli Market, Bangalore, Karnataka, India\",\"Duration\":2475,\"Distance\":19872,\"Error\":null,\"Fares\":[{\"PhoneNo\":null,\"Vehicle\":\"Auto\",\"Fare\":238}]}"
}
请帮帮我

我的网络配置

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1
{



    [OperationContract]
    public string GetFareAndDistanceJson(string source, string destination, string country, string city)
    {

       return new JavaScriptSerializer().Serialize(FareManager.GetFare(source, destination, country, city));

    }
    // Add more operations here and mark them with [OperationContract]
}


在向每个属性添加[DataMember]后工作。在我请求XML时,它返回有效的XML,但没有添加此内容。但我必须添加此内容以返回json

您是否尝试将
[DataMember]
添加到其他属性,您想要吗?谢谢添加[DataMember]后它工作正常
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1
{



    [OperationContract]
    public string GetFareAndDistanceJson(string source, string destination, string country, string city)
    {

       return new JavaScriptSerializer().Serialize(FareManager.GetFare(source, destination, country, city));

    }
    // Add more operations here and mark them with [OperationContract]
}
    <?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />

    </system.web>

    <system.serviceModel>
        <services>
            <service name="MeterupAutoTaxiWebService.Service1">
                <endpoint address="" behaviorConfiguration="MeterupAutoTaxiWebService.Service1AspNetAjaxBehavior"
                    binding="webHttpBinding" contract="MeterupAutoTaxiWebService.Service1" />
            </service>
        </services>
        <behaviors>

            <endpointBehaviors>
                <behavior name="MeterupAutoTaxiWebService.Service1AspNetAjaxBehavior">
              <enableWebScript/>

                </behavior>
            </endpointBehaviors>
            <serviceBehaviors>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
            multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
  <connectionStrings>
    <add name="MeterupAutoTaxiEntities" connectionString="metadata=res://*/MeterupTaxiAutoEntities.csdl|res://*/MeterupTaxiAutoEntities.ssdl|res://*/MeterupTaxiAutoEntities.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost;initial catalog=MeterupAutoTaxi;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>