1
Im在使用我的WCF服务时出现问题,首先尝试在不添加服务引用的情况下使用我的wcf,并且使用channelfactory来使用它时使用basichttpbinding和transfermode缓冲它工作正常,但是当我使用流作为transfermode它给错误错误请求错误WCF中使用basichttpBinding和流式传输模式的错误请求
此处,我打电话给我的服务请看看在此先感谢
public static BasicHttpBinding basicHttpBinding()
{
BasicHttpBinding BasicHttpBinding_IService1 = new BasicHttpBinding();
BasicHttpBinding_IService1.CloseTimeout = TimeSpan.Parse("00:01:00");
BasicHttpBinding_IService1.OpenTimeout = TimeSpan.Parse("00:01:00");
BasicHttpBinding_IService1.ReceiveTimeout = TimeSpan.Parse("00:10:00");
BasicHttpBinding_IService1.SendTimeout = TimeSpan.Parse("00:01:00");
BasicHttpBinding_IService1.AllowCookies = false;
BasicHttpBinding_IService1.BypassProxyOnLocal = false;
BasicHttpBinding_IService1.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
BasicHttpBinding_IService1.MaxBufferSize = 2147483646;
BasicHttpBinding_IService1.MaxBufferPoolSize = 524288;
BasicHttpBinding_IService1.MaxReceivedMessageSize = 2147483646;
BasicHttpBinding_IService1.MessageEncoding = WSMessageEncoding.Text;
BasicHttpBinding_IService1.UseDefaultWebProxy = true;
BasicHttpBinding_IService1.TextEncoding = UTF8Encoding.UTF8;
BasicHttpBinding_IService1.TransferMode = TransferMode.Streamed;
return BasicHttpBinding_IService1;
}
public static EndpointAddress endPointAddress()
{
EndpointAddress endpointAddress = new EndpointAddress("http://localhost:5409/IService.svc");
return endpointAddress;
}
private void button1_Click(object sender, EventArgs e)
{
ChannelFactory<IService> myChannelFactory = null;
myChannelFactory = new ChannelFactory<IService>(basicHttpBinding(), endPointAddress());
IService client = myChannelFactory.CreateChannel();
MessageBox.Show(client.GetData(1));
}
根据您的代码,您使用的是缓冲而不是流式传输模式。也许这是有效的“好”代码。如果我遇到了这个问题,我会确保主机和客户端软件对您使用的模式达成一致。我曾尝试过流式传输,虽然它在服务器内存使用情况良好,但在$ $$中正确运行却是一种痛苦。除非你的项目存在严重的内存限制,否则不要考虑流媒体。 – Brian
感谢您的回复,我需要使用流式传输进行大文件下载 – Angelo
您是否尝试过查看[WCF诊断](http://msdn.microsoft.com/zh-cn/library/ms733025(v = vs.110) ).aspx)的更多细节? –