Hi,
I have a simple web service running and I have a console application client consuming the service. I did have issues getting this running and I had been helped by some wonderful people in this community.
I have another problem: if I want to call the service from the client in a loop, it doesn't work. It works only for the first time and then it just keeps waiting. Why is this happening and how can I resolve it.
The code:
namespace WebService
{
[ServiceContract]
public interface IService
{
[OperationContract(Name="Result")]
[WebGet(UriTemplate = "/")]
Stream Result();
}
public class Service:IService
{
public Stream Result()
{
// read a file from the server and return it as stream
}
}
}
The client:
namespace WebServiceClient
{
[ServiceContract]
public interface IService
{
[OperationContract(Name="Result")]
[WebGet(UriTemplate = "/")]
Stream Result();
}
}
static void Main()
{
Console.WriteLine("Press enter when the service is available");
Console.ReadLine();
// creating factory
HttpChunkingBinding binding = new HttpChunkingBinding();
binding.MaxReceivedMessageSize = 0x7fffffffL;
ChannelFactory<WebServiceClient.IService> factory = new ChannelFactory<WebServiceClient.IService>
(binding, new EndpointAddress("http://localhost/WebService/Service"));
WebServiceClient.IService service = factory.CreateChannel();
for(int i = 0; i < 10; i++)
{
Stream s = service.Result();
// write this stream to a file and close the stream
}
//Closing our channel.
((IClientChannel)service).Close();
}
Thanks,