我写了一个WCF双工服务和客户端.一切正常,直到我尝试在客户端实现中调用.Demand().服务似乎是匿名调用回调方法.我想我错过了如何正确配置服务.
用于创建ServiceHost的代码;
ServiceHost duplex = new ServiceHost(new ServerWCallbackImpl());
NetTcpBinding secureBinding = new NetTcpBinding(SecurityMode.Message);
secureBinding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
duplex.AddServiceEndpoint(typeof(IServerWithCallback),
secureBinding,
"net.tcp://localhost:9080/DataService");
Console.WriteLine(Thread.CurrentPrincipal.Identity.Name); //<-- this correctly shows the current principal
duplex.Open();
if (duplex.State == CommunicationState.Opened)
((ServerWCallbackImpl)duplex.SingletonInstance).Send("Hello World!");
Run Code Online (Sandbox Code Playgroud)
用于创建客户端的代码;
CallbackImpl callbackInstance = new CallbackImpl();
NetTcpBinding secureBinding = new NetTcpBinding(SecurityMode.Message);
secureBinding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
DuplexChannelFactory<IServerWithCallback> cf = new DuplexChannelFactory<IServerWithCallback>(
callbackInstance,
secureBinding,
new EndpointAddress(requestingEndpointAddress));
cf.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
cf.Credentials.Windows.ClientCredential = (NetworkCredential)CredentialCache.DefaultCredentials;
IServerWithCallback srv = cf.CreateChannel(new InstanceContext(callbackInstance));
srv.InitiateConversation();
Run Code Online (Sandbox Code Playgroud)
客户实施:
public void MethodOnClient(string message)
{
Console.WriteLine(Thread.CurrentPrincipal.Identity.Name); // <-- anonymous
PrincipalPermission …Run Code Online (Sandbox Code Playgroud) 我有一个简单的WCF双工TCP服务,我试图以编程方式停止.如果我没有任何连接用户,ServiceHost.Close()非常快,但如果我有一个连接用户,我发现Close()函数需要花费相当多的时间,有时> 30秒.这是通常的行为吗?
另一方面,Abort()几乎是瞬间的,我很想用它代替.
说我有这样的WCF服务合同
[ServiceContract(CallbackContract = typeof(ICallback1),
SessionMode = SessionMode.Required)]
public interface IService1
{
// some methods
}
Run Code Online (Sandbox Code Playgroud)
服务实现已InstanceContextMode.Single设置为InstanceContextMode
和之ICallback1类似
public interface ICallback1
{
[OperationContract]
void Report(int someValue);
}
Run Code Online (Sandbox Code Playgroud)
现在在客户端,我可以有类实现ICallback1
class Callback1 : ICallback1
{
public void Report(int someValue)
{
// alert client
}
}
Run Code Online (Sandbox Code Playgroud)
我像这样创建客户服务引用
Service1Client serviceClient = new Service1Client(new InstanceContext(new CallBack1()));
Run Code Online (Sandbox Code Playgroud)
哪个工作正常.现在的问题是我有一些客户端对回调不感兴趣所以我认为我不需要为这样的客户端实现回调接口所以我试过这个
Service1Client serviceClient = new Service1Client(null);
Run Code Online (Sandbox Code Playgroud)
和
Service1Client serviceClient = new Service1Client(new InstanceContext(null));
Run Code Online (Sandbox Code Playgroud)
两人都报道了parameter cannot be null.我的问题是,如果客户端对回调不感兴趣,如何在不传递回调对象的情况下创建服务引用.唯一的要求是所有客户端都应该使用相同的服务,但我可以重新构建服务.有什么想法吗 ?
编辑:
我也试过 SessionMode = SessionMode.Allowed …
我有一个工作的双工WCF服务WSDualHttpBinding.我的问题是找出一种方法来存储具有唯一ID的回调通道.该服务旨在长期运行.我可以简单地在OperationContext.Current.GetCallbackChannel()调用"Subscribe"方法时获取返回值并将其存储在列表或字典中吗?在连接存活之前,它是否保证有效?
我有一个使用net tcp duplex回调的自托管wcf服务
在客户端,我在Channel和ChennelFactory上听故障事件.当频道出现故障时,客户端将重新创建频道并重新订阅.
在服务器端,我通过调用存储回调通道和存储通道的引用,OperationContext.Current.Channel以便我可以监听此通道上的故障和已关闭事件.出现故障时,服务器将删除该订户.
这大部分时间都在工作,直到最近我发现了一个意外的行为:回调通道在服务器上出现故障,但通道在客户端似乎没问题,这导致客户端在服务器已经删除了该用户和客户端时没有重新订阅不会收到任何回调.
我想在双工通信上,如果一端检测到故障,双工通道应该出现故障.
启用可靠会话并且超时很长(2小时)(这可能会导致客户端无法快速感知故障?)
谁能解释为什么会这样?
另一个问题是它为何会出现故障?我连接了40个客户端,但服务器会在随机时间检测到随机客户端出现故障.
嗨,在双工模式下运行WCF的服务存在很大问题.它泄漏了内存(不多但每天大约80MB)并且在内存分析器与服务一起运行24小时之后我发现大部分内存都byte[]被引入了相当混乱,但我最常引用的结尾是这样的:
而"root"看起来像这样:

我也看到很多ServiceChannel(大约200个)来自回调频道(我认为).
我很确定我每个连接的客户端只能容纳其中的一个.
总体而言,我的问题似乎与此几乎相同:Silverlight Wcf实现中的内存泄漏,但在服务器端.
我甚至尝试过[MTAThread]这里提到的事情:当客户端超时但是它没有解决问题时,WCF服务泄漏句柄和内存.
我只是不认为问题出在我的代码中,因为我OperationContext.Current.GetCallbackChannel<IServiceConnectorCallback>()在我自己的一个对象中获取它之后将回调通道包装起来并且没有泄漏(对于每个内存中的每个客户端只有一个给定快照) - 确保我在几次重置这些回调,因为通道可能会改变(客户端丢失连接或重新连接)但我没有办法处理旧的引用,所以我只删除它们,GC应该做它的工作在他们.
我确实使用PerCall我的服务,所以我根本没有处理我的代码中的那些对象.
除了每隔几天重新启动一次服务之外,我真的不知道如何处理这个问题 - 我现在不想要解决的问题:(
所以请给我一些帮助/提示 - 非常感谢你!
我试图使用命名管道在同一台机器上的服务器和客户端进程之间进行通信.服务器向客户端发送消息,客户端对其执行某些操作并返回结果,服务器应该得到结果.
这是服务器的代码:
using System;
using System.IO;
using System.IO.Pipes;
class PipeServer
{
static void Main()
{
using (NamedPipeServerStream pipeServer =
new NamedPipeServerStream("testpipe", PipeDirection.InOut))
{
Console.WriteLine("NamedPipeServerStream object created.");
// Wait for a client to connect
Console.Write("Waiting for client connection...");
pipeServer.WaitForConnection();
Console.WriteLine("Client connected.");
try
{
// Read user input and send that to the client process.
using (StreamWriter sw = new StreamWriter(pipeServer))
{
sw.AutoFlush = true;
Console.Write("Enter text: ");
sw.WriteLine(Console.ReadLine());
}
pipeServer.WaitForPipeDrain();
using (StreamReader sr = new StreamReader(pipeServer))
{
// Display the read …Run Code Online (Sandbox Code Playgroud) 我在C#上使用WIA。当我将属性“页面”设置为1并将“文档处理选择”设置为5(以启用AFD和双面扫描)时,方法“ wiaCommonDialog.ShowTransfer”出现异常。
例外是“ System.OutOfMemoryExcepion”。
你能帮我解决吗?我使用正确的值吗?
try
{
SetWIAProperty(device.Properties, "3096", 1);//pages to 1
SetWIAProperty(device.Properties,"3088",5);//Handling select to 5
if (init == false)
{
init = true;
}
wiaCommonDialog = new WIA.CommonDialog();
while (true)
{
object imgFile = (ImageFile)wiaCommonDialog.ShowTransfer(item,WIA.FormatID.wiaFormatJPEG,false);//Here the exception is shown
object imgFile2=(ImageFile)wiaCommonDialog.ShowTransfer(item, WIA.FormatID.wiaFormatJPEG, false);
if (imgFile != null)
{
imagenes.Add((ImageFile)imgFile);
leyo = true;
}
if (imgFile2 != null)
{
imagenes.Add((ImageFile)imgFile2);
leyo = true;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用 C# 开发一个应用程序来使用 WIA 2.0 库。目前我可以使用大部分功能,例如 ADF(自动文档进纸器)、过滤器等等。
现在,我需要使用扫描仪(富士通)的双面打印器。
我正在尝试将 WIA_DPS_DOCUMENT_HANDLING_SELECT 扫描仪属性设置为 DUPLEX 值。请参阅下面的代码:
try
{
bool hasMorePages = false;
//determine if there are any more pages waiting
Property documentHandlingSelect = null;
Property documentHandlingStatus = null;
foreach (Property prop in WiaDev.Properties)
{
if (prop.PropertyID == WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_SELECT)
documentHandlingSelect = prop;
if (prop.PropertyID == WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_STATUS)
documentHandlingStatus = prop;
}
object obj = new object();
obj = (WIA_DPS_DOCUMENT_HANDLING_SELECT.DUPLEX);
documentHandlingSelect.set_Value(ref obj);
if (documentHandlingSelect != null) //may not exist on flatbed scanner but required for feeder …Run Code Online (Sandbox Code Playgroud) 我想知道,
第一个问题:每个对等点使用一个套接字(全双工)与两个套接字(单工)的优缺点是什么:一个用于读取,另一个用于写入?特别是在性能和资源利用率方面。
第二个问题以防万一,如果我选择在每个对等点上使用超过 1 个套接字,那么我所做的所有读写操作都是如此。那么它会帮助我扩展处理未处理的消息吗?
第三个问题:什么可以帮助我确定每个对等点的套接字数量?网络带宽?传入和传出的消息数量?
所有问题都是不同的,没有任何相互关系。
duplex ×10
c# ×6
wcf ×6
wia ×2
c#-4.0 ×1
callback ×1
exception ×1
imaging ×1
memory-leaks ×1
named-pipes ×1
networking ×1
service ×1
servicehost ×1
sockets ×1