读书人

wcf 启动时报错协约需要双工 nettcp协

发布时间: 2013-04-20 19:43:01 作者: rapoo

wcf 启动时报错协定需要双工 nettcp协议
host = new ServiceHost(typeof(WcfServiceLibrary3.Service1));
if (host.State != CommunicationState.Opening || host.State != CommunicationState.Opened)
{
host.Open();

MessageBox.Show("启动成功");
}
else
{
MessageBox.Show("已经启动");
}

*******************************************************************
[ServiceContract(Namespace="",SessionMode=SessionMode.Allowed, CallbackContract = typeof(IMessageCallBack))]
public interface IService1
{
[OperationContract]
string GetData(int value);

[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);

[OperationContract]
void UpLoadFile(FileData files);

[OperationContract]
void UpLoadFiles(FileType FileType);

[OperationContract]
void UpLoadFilesss(List<FileType> FileTypes);

// TODO: 在此添加您的服务操作
}

public interface IMessageCallBack
{
[OperationContract(IsOneWay=true)]
void OnMessageAdded(string message);
}



[解决办法]
transferMode="Streamed"
必须改为
transferMode="Buffered"

Streamed模式不支持双工。
[解决办法]

引用:
换成 buffered 传大文件就传不了啦 报错 套接字连接已终止

分为2个服务地址提供服务,一个启用双工,用Buffered模式,另一个不用双工,使用Streamed模式。或者你就舍弃双工,去掉“SessionMode=SessionMode.Allowed, CallbackContract = typeof(IMessageCallBack)”,那些根本就没必要使用。
自己看WCF传输模式的限制:http://msdn.microsoft.com/ZH-CN/library/vstudio/system.servicemodel.transfermode(v=vs.110).aspx
[解决办法]
你的endpoint 的address用绝对地址看看,同时将对应的baseAddresses删除,一般是不用的,除非需要提供http的引用才会需要,但是那样协议就应该是http而不是net.Tcp

读书人网 >C#

热点推荐