0

ILeaveManagement class

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

LeaveManagement class

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>();
                }
            }
}

configuration

<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>

I have deployed the project in IIS 7.5. When i run the application , it is saying BadRequest.

I have verrified in fiddler. i saw 400 error.

Please help me on this.

Siva P
  • 109
  • 1
  • 12

2 Answers2

0

Try using webHttpBinding in your endpoint instead of the wsHttpBinding, or add it as an additional one and change the address. I use a bindingNamespace in my project, but I don't think you need it.

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

Add an Endpoint Behavior

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

I also annotate the OperationContract slightly differently, but it shouldn't make all that much of a difference. I'll give it to you just in case...

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

To call the service, it would look like this using the XMLService endpoint name:

http://myWebHost.com/WebService/MyService.svc/XMLService/GetLeaveDetails
Mike
  • 3,186
  • 3
  • 26
  • 32
0

Hosting an wcf service into a website issue : System.ArgumentException: ServiceHost only supports class service types

the above link helped me to solve my issue.

<%@ ServiceHost Language="C#" Debug="true" Service="restleave.ProductRESTService" %>
Community
  • 1
  • 1
Siva P
  • 109
  • 1
  • 12