I've developed and Deployed Rest Enabled WCF Services on the IIS but when I call those Services from the browser or My Asp.Net Mvc Consumer I get a 400 Bad Request Error. I've also tried debugging the services through WCFStorm.REST client in which I get the following error:
System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at RestSharp.Http.GetRawResponse(HttpWebRequest request)
at RestSharp.Http.GetResponse(HttpWebRequest request)
Here is my WCF Configuration:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpConfig"
allowCookies="true"
maxReceivedMessageSize="20000000"
maxBufferSize="20000000"
maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32"
maxArrayLength="200000000"
maxStringContentLength="200000000" />
</binding>
<binding name="webHttpsConfig"
allowCookies="true"
maxReceivedMessageSize="20000000"
maxBufferSize="20000000"
maxBufferPoolSize="20000000">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
<readerQuotas maxDepth="32"
maxArrayLength="200000000"
maxStringContentLength="200000000" />
</binding>
<binding name="webHttpBindingXML" />
<binding name="webHttpBindingJSON" />
</webHttpBinding>
</bindings>
<services>
<service name="BusinessServices.UserService">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpsConfig" contract="BusinessServices.IUserService" behaviorConfiguration="web">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="XML" binding="webHttpBinding" bindingConfiguration="webHttpBindingXML" contract="BusinessServices.IUserService" behaviorConfiguration="RestXMLEndpointBehavior" />
<endpoint address="JSON" binding="webHttpBinding" bindingConfiguration="webHttpBindingJSON" contract="BusinessServices.IUserService" behaviorConfiguration="RestJSONEndpointBehavior" />
<host>
<baseAddresses>
<add baseAddress="https://localhost:7743/UserService.svc" />
</baseAddresses>
</host>
</service>
<service name="BusinessServices.RoleService">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpConfig" contract="BusinessServices.IRoleService" behaviorConfiguration="web">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="XML" binding="webHttpBinding" bindingConfiguration="webHttpBindingXML" contract="BusinessServices.IRoleService" behaviorConfiguration="RestXMLEndpointBehavior" />
<endpoint address="JSON" binding="webHttpBinding" bindingConfiguration="webHttpBindingJSON" contract="BusinessServices.IRoleService" behaviorConfiguration="RestJSONEndpointBehavior" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:7742/RoleService.svc" />
</baseAddresses>
</host>
</service>
<service name="BusinessServices.CriminalService">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpConfig" contract="BusinessServices.ICriminalService" behaviorConfiguration="web">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="XML" binding="webHttpBinding" bindingConfiguration="webHttpBindingXML" contract="BusinessServices.ICriminalService" behaviorConfiguration="RestXMLEndpointBehavior" />
<endpoint address="JSON" binding="webHttpBinding" bindingConfiguration="webHttpBindingJSON" contract="BusinessServices.ICriminalService" behaviorConfiguration="RestJSONEndpointBehavior" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:7742/CriminalService.svc" />
</baseAddresses>
</host>
</service>
<service name="BusinessServices.NationalityService">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpConfig" contract="BusinessServices.INationalityService" behaviorConfiguration="web">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="XML" binding="webHttpBinding" bindingConfiguration="webHttpBindingXML" contract="BusinessServices.INationalityService" behaviorConfiguration="RestXMLEndpointBehavior" />
<endpoint address="JSON" binding="webHttpBinding" bindingConfiguration="webHttpBindingJSON" contract="BusinessServices.INationalityService" behaviorConfiguration="RestJSONEndpointBehavior" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:7742/NationalityService.svc" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
<behavior name="RestJSONEndpointBehavior">
<webHttp helpEnabled="true" defaultOutgoingResponseFormat="Json" />
</behavior>
<behavior name="RestXMLEndpointBehavior">
<webHttp helpEnabled="true" defaultOutgoingResponseFormat="Xml" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="webHttpBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
ASP.NET MVC Client Endpoints:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="WebHttpBinding_ICriminalService" />
<binding name="WebHttpBinding_IRoleService" />
<binding name="WebHttpsBinding_IUserService" />
<binding name="WebHttpBinding_INationalityService" />
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="webEndpoint">
<webHttp defaultBodyStyle="Wrapped" helpEnabled="true"/>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://localhost:7742/CriminalService.svc" behaviorConfiguration="webEndpoint" binding="webHttpBinding" bindingConfiguration="WebHttpBinding_ICriminalService" contract="CriminalServiceReference.ICriminalService" name="WebHttpBinding_ICriminalService" />
<endpoint address="http://localhost:7742/RoleService.svc" behaviorConfiguration="webEndpoint" binding="webHttpBinding" bindingConfiguration="WebHttpBinding_IRoleService" contract="RoleServiceReference.IRoleService" name="WebHttpBinding_IRoleService" />
<endpoint address="https://localhost:7743/UserService.svc" behaviorConfiguration="webEndpoint" binding="webHttpBinding" bindingConfiguration="WebHttpsBinding_IUserService" contract="UserServiceReference.IUserService" name="WebHttpsBinding_IUserService" />
<endpoint address="http://localhost:7742/NationalityService.svc" behaviorConfiguration="webEndpoint" binding="webHttpBinding" bindingConfiguration="WebHttpBinding_INationalityService" contract="NationalityServiceReference.INationalityService" name="WebHttpBinding_INationalityService" />
</client>
</system.serviceModel>
A Sample Service Contract:
[ServiceContract]
[ValidationBehavior]
public interface INationalityService : IDisposable
{
[OperationContract]
[FaultContract(typeof(ValidationFault))]
[WebInvoke(UriTemplate = "", Method = "POST")]
void Create(NationalityDTO Nationality);
[OperationContract]
[FaultContract(typeof(ValidationFault))]
[WebGet(UriTemplate = "")]
IEnumerable<NationalityDTO> GetNationalities();
}
P.S.: I've tried almost everything that's possible and available on internet / SO but to no avail. Thanks in advance.
Update:- I've tried to debug the Services Project as a Visual Studio Startup Project but there it runs fine in isolation. The problem occurs only when the one published and hosted on IIS is accessed.