Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# c中WCF服务的裸Json响应#_C#_Asp.net_Json_Wcf_Jquery - Fatal编程技术网

C# c中WCF服务的裸Json响应#

C# c中WCF服务的裸Json响应#,c#,asp.net,json,wcf,jquery,C#,Asp.net,Json,Wcf,Jquery,我在.NET4平台中创建了一个WCF服务,当我用jQueryAjax帖子点击它时,它返回JSON。 我所遇到的问题是,我更希望POST的json响应不使用带有结果后缀的方法名称包装 详细内容: public interface IService { [OperationContract] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodySt

我在.NET4平台中创建了一个WCF服务,当我用jQueryAjax帖子点击它时,它返回JSON。 我所遇到的问题是,我更希望POST的json响应不使用带有结果后缀的方法名称包装

详细内容:

public interface IService
{
    [OperationContract]
    [WebInvoke(Method = "POST",
 ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
    Person GetInfo(string id);
}

[AspNetCompatibilityRequirements(RequirementsMode
    = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service: Iservice
{
    public Person GetInfo(string id)
    {
           ...
           return new Person();
    }
}

public class Person
{
  public string FirstName;
  public string LastName;

  public Person(){
   FirstName = "Jon";
   LastName = "Doe";
  }
}

web.config
<system.serviceModel>
   <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
   <behaviors>
     <serviceBehaviors>
       <behavior name="ServiceBehavior">
         <serviceMetadata httpGetEnabled="true"/>
         <serviceDebug includeExceptionDetailInFaults="true"/>
       </behavior>
     </serviceBehaviors>
     <endpointBehaviors>
       <behavior name="EndpBehavior">
         <webHttp/>
       </behavior>
     </endpointBehaviors>
   </behaviors>
   <services>
     <service behaviorConfiguration="ServiceBehavior" name="Service">
       <endpoint address="" binding="webHttpBinding"
           contract="IService" behaviorConfiguration="EndpBehavior"/>
     </service>
   </services>
 </system.serviceModel>
使用
BodyStyle=WebMessageBodyStyle.Wrapped
在我的javascript代码中得到的响应是:

{"GetInfoResult" : {"FirstName":"Jon", "LastName":"Doe"}}
但是当我将其更改为
WebMessageBodyStyle.Bare
并且其他所有内容都保持不变时,会发生500内部服务器错误

在没有方法+结果包装器的情况下,是否可以在我的POST响应中返回裸json?如果是,我做错了什么


提前感谢

我认为
WebMessageBodyStyle.Bare
也需要一个“Bare”请求,并且您正在从javascript代码发送一个对象,类似这样:
{id:'value}
,它将被翻译为:

public class DTObject{
  public string Id { get; set; }
}
并且您的操作方法只需要一个
字符串
作为参数

尽量只让你的回答像这样“赤裸裸”
WebMessageBodyStyle.WrappedRequest

[编辑]

public class DTObject{
  public string Id { get; set; }
}