2012-03-16 75 views
2

在基于IIS中的基于WCF Rest的服务中,出现以下问题。WCF REST和IIS Express 7.5返回请求错误(400)

接口:

[ServiceContract] 
public interface ITestService 
{ 
    [OperationContract] 
    [WebInvoke(Method = "GET", UriTemplate = "/GetEmployee/{userid}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.Bare)] 
    IEnumerable<Employee> GetPlans(string userid); 
} 

TestService.svc.cs:

public class TestService : ITestService 
{ 
    public IEnumerable<Employee> GetEmployee(string userid) 
    {  
     return Employee 
    } 
} 

当我使用卡西尼服务器,它工作在JSON格式精细returnштп结果。网址如下:

http://localhost:58764/TestService/TestService.svc/GetEmployee/2 

但是当我主持,在IIS快递7.5在URL:

http://localhost/TestService/TestService.svc/GetEmployee/2) 

它只是说:

“请求错误

服务器在处理请求时遇到错误,请参阅服务帮助页面,以便为服务构建有效的请求。“

http://localhost/TestService/TestService.svc/help 

返回所有可用的方法没有任何问题的URL。

+0

您确定Employee对象是可序列化的吗?有时通过cassini的序列化通过,但在IIS上托管时失败。在IIS上托管时,请尝试在您的服务上启用跟踪,以获取您的请求失败原因的确切原因。可能是由于返回的数据大小所致 – Rajesh 2012-03-16 09:00:22

回答

0

不确定这个问题。

你可以尝试重新安装.net框架吗?

  • 打开Visual Studio 2010命令提示符
  • 类型 “ASPNET_REGIIS -i”,然后按回车
  • 重新启动IIS如果IIS安装WCF组件具有

  • 检查。如果没有安装。以下命令,然后重新启动

  • 运行IIS C:\ WINDOWS \ Microsoft.NET \框架\ 3.0 \ Windows通信基础>服务 ModelReg.exe -i

之后尝试。希望它能工作,我有类似的问题,这些步骤后解决。

+0

谢谢Shailesh。我尝试了这些步骤,但问题仍然存在。之后,我尝试了SVCTraceViewer.exe,发现问题是因为模仿问题。最后我解决了它。 – Naveen 2012-03-19 07:36:09

相关问题