I have a WCF-REST service with one method which returns a string:
[ServiceContract]
public interface IService
{
[WebInvoke(UriTemplate = "/getastring/")]
[OperationContract]
string GetAString(string input);
}
public class Service : IService
{
public string GetAString(string input)
{
Trace.WriteLine("GetAString");
return input;
}
}
The service is hosted with a WebHttpBinding and the TransferMode is set to Streamed
ServiceHost streamedHost = new ServiceHost(typeof(Service), new Uri("http://localhost/streamed"));
WebHttpBinding streamedBinding = new WebHttpBinding();
streamedBinding.TransferMode = TransferMode.Streamed;
ServiceEndpoint streamedEndpoint = streamedHost.AddServiceEndpoint(typeof(IService), streamedBinding, string.Empty);
streamedEndpoint.Behaviors.Add(new ErrorWebHttpBehavior());
streamedHost.Open();
When the service is accessed with a .NET-Client everything is fine.
When I use a Java-Client with Jersey, the following exception occurs:
An operation was attempted on a nonexistent network connection
The only happens when the TransferMode is set to Streamed.
The following Java code is used:
Client client = Client.create(new DefaultClientConfig());
WebResource service = client.resource(UriBuilder.fromUri("http://localhost").build());
String result = service.path("regular/getastring").type(MediaType.APPLICATION_JSON).post(String.class, "123");
System.out.println(result);
Is there a way to consume the streamed WCF service without this exception?
Sample project: http://dl.dropbox.com/u/21096596/WCF-Jersey.zip
The problem does not appear if streaming is only enabled for the response.
Setting
TransferMode = TransferMode.StreamedResponse;in the binding configuration fixes the problem for us.