2014-03-19 169 views
0

ILeaveManagementWCF REST服务无法正常工作

[ServiceContract] 
    public interface ILeaveManagement 
    {    
     [OperationContract] 
     [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, 
        BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "get")] 
     List<ServiceReference1.LeaveRequest> GetLeaveDetails(); 
    } 

LeaveManagement

public class LeaveManagement : ILeaveManagement 
    { 

    public List<ServiceReference1.LeaveRequest> GetLeaveDetails() 
      { 
       try 
       { 
        var entities = new ServiceReference1.leaverequest_Entities(new Uri(serviceUrl));    
        var result = entities.LeaveRequestCollection; 
        return result.ToList(); 
       } 
       catch 
       { 
        return new List<ServiceReference1.LeaveRequest>(); 
       } 
      } 
} 

配置

<service behaviorConfiguration="DRLExternalList.LeaveManagementBehavior" name="DRLExternalList.LeaveManagement"> 
     <endpoint address="" binding="wsHttpBinding" contract="DRLExternalList.ILeaveManagement"/> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
     </service> 

<behavior name="DRLExternalList.LeaveManagementBehavior"> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 

我有在IIS 7.5中部署该项目。当我运行应用程序时,它说BadRequest。

我已经在提琴手中进行了验证。我看到了400错误。

请帮我解决这个问题。

回答

0

尝试在您的端点中使用webHttpBinding而不是wsHttpBinding,或者将其添加为另一个并更改地址。我在我的项目中使用了bindingNamespace,但我不认为你需要它。

<endpoint address="XMLService" 
       binding="webHttpBinding" 
       behaviorConfiguration="restXMLBehavior" 
       contract="DRLExternalList.ILeaveManagement"> 
    </endpoint> 

添加的终结点行为

<endpointBehaviors> 
    <!-- Behavior for the REST endpoint --> 
    <behavior name="restXMLBehavior"> 
     <webHttp helpEnabled="true"/> 
    </behavior> 
    </endpointBehaviors> 

我也注释OperationContract的略有不同,但它不应该使所有多大的差别。我就给你万一......

[WebGet(UriTemplate = "/GetLeaveDetails", ResponseFormat = WebMessageFormat.Xml)] 

调用服务,它看起来像这样使用XMLService端点名称:

http://myWebHost.com/WebService/MyService.svc/XMLService/GetLeaveDetails