我有一個簡單的Web服務運行,我有一個控制檯應用程序客戶端使用該服務。我確實遇到了一些問題,我得到了這個社區一些優秀人士的幫助。消費WCF Web服務
我還有一個問題:如果我想在循環中從客戶端調用服務,它不起作用。它只在第一次工作,然後它一直在等待。爲什麼會發生這種情況,我該如何解決這個問題。
代碼:
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();
}
感謝,
帖子你的代碼和異常消息。 – Juliet 2010-06-10 19:36:02
你能發表一些代碼嗎?調試web服務的一個好方法是使用Fiddler觀察HTTP流量。 – Alan 2010-06-10 19:36:50
你使用什麼技術? – tster 2010-06-10 19:40:53