I have suddenly started facing the below issue. My REST Service no more works. It was working sometime ago and I didn't make any changes to config. As of sudden, it is behaving weird. I used WCF Test client to check the issue and strangely, the service method gets called 6 times and finally throws the below error.
Error: Cannot obtain Metadata from http://localhost:49796/Test.svc/GetInformation?memberId=1
If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:49796/Test.svc/GetInformation?memberId=1
Metadata contains a reference that cannot be resolved: 'http://localhost:49796/Test.svc/GetInformation?memberId=1
'. The remote server returned an unexpected response: (405) Method Not Allowed. The remote server returned an error: (405) Method Not Allowed.HTTP GET Error URI:
http://localhost:49796/Test.svc/GetInformation?memberId=1
There was an error downloading 'http://localhost:49796/Test.svc/GetInformation?memberId=1'. The underlying connection was closed: An unexpected error occurred on a receive. Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. An existing connection was forcibly closed by the remote host
The most surprising part is that it is same even if I create a new service or test an old service. Did something went wrong in my pc globally? It appears to be some file corruption or change in config globally somewhere as all of WCF REST Services in my pc behaves the same. I googled but could not find any proper answer.
I tried removing end point and tested again using Test Client. As test client adds basichttpbinding automatically, it is working fine using test client.
Please advise on the fix, if anyone is aware.
my config looks like below:
<system.serviceModel>
<services>
<service name="TestService.ServiceLayer.Services.TestService" behaviorConfiguration="TestBehavior">
<endpoint address="" binding="webHttpBinding"
contract="TestService.ServiceLayer.Services.ITestService" behaviorConfiguration="web" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="TestBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
My Service contract is as below
[ServiceContract]
public interface ITestService
{
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetInformation?memberId={memberId}")]
List<MyTestClass> GetInformation(string memberId);
}
I have analyzed further and found that if I change List to string it works fine. I added KnownType as well on top of service contract but it doesn't work. Please advise on this line.