I’ve written a C# Windows Service that provides a REST api through WCF. This Service needs to call another web service which also uses a REST api. My service can communicate perfectly with the other service unless someone has made a call my service and it is currently responding. I wrote up a simple test:
public void TestConnection()
{
WebChannelFactory<IOtherService> wf = new WebChannelFactory<IOtherService>(otherURI);
IOtherService service = wf.CreateChannel();
service.Test();
}
[ServiceContract]
public interface IOtherService
{
[WebGet(UriTemplate = "services/account?username=testuser&password=d625a4de623dce36af2b75102eaf0ce7&locale=en-US", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
[OperationContract]
AccountServiceInfo Test();
}
Normally when I call TestConnection it works perfectly, but when someone makes a call to my service that requires me to call TestConnection the other service sees a POST rather than a GET and returns 400. Does anyone have any idea why this might be the case or how I can fix it? Thanks.
When using a
WebChannelFactoryinside a WCF service that already has anOperationContext, you may need to create a new context before being able to successfully callout using a channel created by theWebChannelFactory.http://blogs.msdn.com/b/pedram/archive/2008/07/19/webchannelfactory-inside-a-wcf-service.aspx