When I try to invoke to my WCF method using the WCF Test Client, I get the following error message:
Failed to invoke the service. Possible causes: The service is offline or
inaccessible; the client-side configuration does not match the proxy; the existing
proxy is invalid. Refer to the stack trace for more detail. You can try to recover
starting a new proxy, restoring to default configuration, or refreshing the
service.
The underlying connection was closed: The connection was closed unexpectedly.
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at MyApi.GetStuff(String[] stuff)
at IMyApi.GetStuff(String[] stuff)
Inner Exception:
The underlying connection was closed: The connection was closed unexpectedly.
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
I have my method under test so I know the exception isn't being thrown from inside the method. I also have an interceptor Interceptor: Attribute, IOperationBehavior, IParameterInspector
whose AfterCall
method is reporting that the interceptor was reached. It seems pretty clear from the exception message, the unit tests, and the interceptor that the exception is somehow being thrown AFTER the method is invoked, when the service attempts (but fails) to send the response.
I am using Visual Studio's built-in support for WCF. I didn't do anything to put it on IIS. Other methods in the API seem to work just fine - just that one doesn't. What is going wrong?
EDIT: After some debugging, I found that the following code reproduces my problem.
[ServiceContract]
public class TestService
{
[OperationContract]
public MyClass DoWork()
{
return new MyClass()
{
Str = "hello"
};
}
}
[DataContract]
public class MyClass
{
[DataMember]
public string Str { get; set; }
[DataMember]
public string StrPlus
{
get { return Str + " again!"; }
}
}
How come adding StrPlus throws the exception?