ILeaveManagement 类
[ServiceContract]
public interface ILeaveManagement
{
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "get")]
List<ServiceReference1.LeaveRequest> GetLeaveDetails();
}
离开管理类
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 :(得分: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
答案 1 :(得分:0)
以上链接帮助我解决了我的问题。
<%@ ServiceHost Language="C#" Debug="true" Service="restleave.ProductRESTService" %>