在后wcf服务中获取空值

在后wcf服务中获取空值,wcf,web-services,rest,wcf-data-services,Wcf,Web Services,Rest,Wcf Data Services,我正在写一个WCF服务。下面是服务端实现 [OperationContract(Name="GetMediaFile")] [Description(ServiceDescConstants.GetMediaFile)] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = UriT

我正在写一个WCF服务。下面是服务端实现

    [OperationContract(Name="GetMediaFile")]
    [Description(ServiceDescConstants.GetMediaFile)]
    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = UriTemplateConstants.GetMediaFile)]        
    Stream GetMediaFile(string type, string mediaId);
  public Stream GetMediaFile(string type, string mediaId)
    {
            CustomerBL customerBl = new CustomerBL();
            return customerBl.getMediaFile(Convert.ToInt32(type), Convert.ToInt32(mediaId));            
    }
在哪里

UriTemplateConstants.GetMediaFile = "GetMediaFile?type={type}&mediaId={mediaId}";
下面是接口方法的实现

    [OperationContract(Name="GetMediaFile")]
    [Description(ServiceDescConstants.GetMediaFile)]
    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = UriTemplateConstants.GetMediaFile)]        
    Stream GetMediaFile(string type, string mediaId);
  public Stream GetMediaFile(string type, string mediaId)
    {
            CustomerBL customerBl = new CustomerBL();
            return customerBl.getMediaFile(Convert.ToInt32(type), Convert.ToInt32(mediaId));            
    }
在客户端,我使用RestClient插件来测试服务。 这是我正在发送的数据

URL:customersite/GetMediaFile 标题:内容类型=x-www-form-urlencoded 正文:type=0和mediaId=1

任何帮助


现在的问题是我得到了空值

修改接口方法:

[OperationContract(Name = "GetMediaFile")]
[Description(ServiceDescConstants.GetMediaFile)]
[WebInvoke(Method = "POST", 
    ResponseFormat = WebMessageFormat.Json, 
    BodyStyle = WebMessageBodyStyle.Wrapped, 
    UriTemplate = "/GetMediaFile")]
Stream GetMediaFile(Stream input);
并修改其实现:

public Stream GetMediaFile(Stream input)
{
    StreamReader sr = new StreamReader(input);
    string s = sr.ReadToEnd();
    sr.Dispose();
    NameValueCollection qs = HttpUtility.ParseQueryString(s);
    string type = qs["type"];
    string mediaId = qs["mediaId"];

    CustomerBL customerBl = new CustomerBL();
    return customerBl.getMediaFile(Convert.ToInt32(type), Convert.ToInt32(mediaId));
}
在web.config中,使用以下配置(确保使用自己的名称空间/类/接口名称):

解决方案是对Edgardo Rossetto博客文章的改编