Egy self-hosted WCF szolgaltatason dolgozok.
NetTcpBinding-et hasznalok Streamed TransferMode-dal, mert nagy file-okat is atkuldok. A rendszer mukodik.
Most fejleszteni szeretnem, ugy, hogy duplex legyen, callback-et tehessek bele.
A kerdesem: Ez lehetseges? Lehet NetTcpBinding Streamed TransferMode-dal duplex?
Kerlek benneteket, hogy CSAK self-hosted, azaz kodbol host-olt peldat adjatok!!!!!
Ime a hatter:
IMyDataService.cs
[ServiceContract(CallbackContract = typeof(INotifyCallback))] public interface IMyDataService { [OperationContract(ProtectionLevel = System.Net.Security.ProtectionLevel.None)] [FaultContract(typeof(MyFaultException))] [FaultContract(typeof(MyUserAlreadyLoggedInFaultException))] [FaultContract(typeof(AuthorizationFaultException))] Guid Authenticate(Guid clientID, string userName, string password, bool forceLogin); }
INotifyCallback.cs
public interface INotifyCallback { [OperationContract(IsOneWay = true)] void ShowMessageBox(string message); }
Sajat ServiceHost class-t hasznalok:
public class CertificateServiceHost : ServiceHost { public CertificateServiceHost(Type serviceType, Uri[] baseAddresses) : base(serviceType, baseAddresses) { }
public CertificateServiceHost(object singletonInstance, Uri[] baseAddresses) : base(singletonInstance, baseAddresses) { }
public CertificateServiceHost(object singletonInstance) : base(singletonInstance) { }
protected override void ApplyConfiguration() { base.ApplyConfiguration(); //... }
protected override void InitializeRuntime() { NetTcpBinding tcpBinding = new NetTcpBinding(); tcpBinding.TransferMode = TransferMode.Streamed; tcpBinding.Security.Mode = SecurityMode.None; // TODO! tcpBinding.MaxBufferPoolSize = 2147483647; tcpBinding.MaxReceivedMessageSize = 2147483647; tcpBinding.ReaderQuotas.MaxDepth = 2147483647; tcpBinding.ReaderQuotas.MaxStringContentLength = 2147483647; tcpBinding.ReaderQuotas.MaxArrayLength = 2147483647; tcpBinding.ReaderQuotas.MaxBytesPerRead = 2147483647; tcpBinding.ReaderQuotas.MaxNameTableCharCount = 2147483647;
ServiceMetadataBehavior metadataBehavior = new ServiceMetadataBehavior(); this.Description.Behaviors.Add(metadataBehavior);
this.AddServiceEndpoint(typeof(IMetadataExchange), tcpBinding, "MEX"); this.AddServiceEndpoint(typeof(IMyDataService), tcpBinding, "MyDataService");
base.InitializeRuntime(); } }
Amikor megrpbalom elinditani a kiszolgalast:
MyDataService singleton = new MyDataService(); tcpServiceHost = new CertificateServiceHost(singleton, baseAddresses); tcpServiceHost.Closed += new EventHandler(host_Closed); tcpServiceHost.Closing += new EventHandler(host_Closing); tcpServiceHost.Faulted += new EventHandler(host_Faulted); tcpServiceHost.UnknownMessageReceived += new EventHandler<UnknownMessageReceivedEventArgs>(host_UnknownMessageReceived); tcpServiceHost.Opened += new EventHandler(host_Opened);
tcpServiceHost.Open(); MyDataService service = (MyDataService)tcpServiceHost.SingletonInstance;
Open()-re exception-t kapok.
A 'tcpBinding.TransferMode = TransferMode.Streamed' nelkul ugy tunik, hogy mukodik. Azaz csak Streamed modban nem megy.
Az exception a kovetkezot mondja:
"Contract requires Duplex, but Binding 'NetTcpBinding' doesn't support it or isn't configured properly to support it."
Az allitasnak egyatalan melyik fele az igaz? Lehet ilyet csak nem jol konfiguraltam? Hogyan konfiguralhatnam jol kodbol?
Van otletetek? |