我如何编写一个简单的 - 最简单的工作 - 测试应用程序,说明如何使用IPC /命名管道?
例如,如何编写一个控制台应用程序,程序1将"Hello World"写入程序2,程序2接收消息并将"Roger That"回复给程序1.
之前,我能够在Visual Studio 2013下运行特定项目的单元测试.这最近停止了工作,没有对项目进行重大改变,不幸的是,我不记得它什么时候做了最后一次工作,也没有改变.但是,对项目本身的任何修改都是最小的(一个或两个新方法),并且不涉及任何配置文件更改或类似的频繁报告的问题.我相信Visual Studio(可能是最近的更新)或插件或第三方软件的更改导致了以下问题.
加载项目时,一分钟后,"输出"窗口中的"测试"输出显示:
------发现测试开始------
无法初始化客户端代理:无法连接到测试进程vstest.discoveryengine.x86.exe.
==========发现测试结束:0找到(0:00:59.8853102)==========
类似于以前报告的问题,只是调试停止工作,以管理员身份运行Visual Studio似乎"解决"了这个问题.然而,这只是表明问题可能与访问权限有关.
我发现了一个相关的Microsoft Connect错误报告,该报告还暗示了由第三方应用程序引起的问题.显然vstest.discoveryengine.x86.exe使用命名管道进行通信devenv.exe.另一个应用程序可能会使用该请求,从而导致Visual Studio连接失败.但是,验证哪些命名管道正在使用中,我没有找到任何立即明显的罪魁祸首.我还想象连接可能由于其他原因而失败.
启用日志记录后 devenv.exe,vstest.executionengine.exe和vstest.discoveryengine.exe我发现与在devenv的日志中发现引擎但下列情况除外:
E, 10048, 42, 2014/12/22, 01:47:13.683, 63637924754, devenv.exe, TestRunnerServiceClient: Could not connect to test runner service within the available time 60000. Reason:System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at net.pipe://steven-flip/vstest.discoveryengine/8232 that could accept the message. This is often caused by an incorrect address or SOAP action. See …Run Code Online (Sandbox Code Playgroud) 几天前,我成功实现了Windows服务中托管的WCF服务.StackOverflow的社区帮助我在这里进行了WSDL曝光.我再次感谢你.但是最近我发现这次服务还有另一个潜在的客户端,它位于与服务相同的机器上,这使我认为我应该使用namedPipesBinding添加另一个端点.
就我而言,命名管道似乎是机内通信的最佳解决方案.如果这是错误的请纠正我.
我需要为同一服务/合同公开另一个端点,但这次使用netNamedPipeBinding.但是我真的不明白如何从客户端添加服务引用.加入后愚蠢地说
<endpoint address="net.pipe://localhost/OfficeService"
binding="netNamedPipeBinding"
contract="netBridge.Development.OfficeService.IWordService"
bindingConfiguration="localBinding" />
Run Code Online (Sandbox Code Playgroud)
我试图在位于同一台机器上的Windows窗体应用程序中添加一个服务引用,键入net.pipe:// .... url.它没用.我必须提到我之前删除了mex(MetaData Exchange)端点,因为我认为没有必要.
[DllImport("kernel32.dll")]
private static extern Int32 AllocConsole();
Run Code Online (Sandbox Code Playgroud)
我可以使用此命令打开cmd.exe.但我只能打开一个控制台窗口并写入其中.我怎么能打开另一个?打开两个控制台窗口是否有干净,快速的解决方案?
我收到以下错误:
在net.pipe:// localhost/ServiceModelSamples/service上没有可以接受该消息的端点.这通常是由错误的地址或SOAP操作引起的.有关更多详细信息,请参阅InnerException(如果存在).
我在另一个WCF调用中调用Windows服务中的WCF自托管服务,如下所示.
_host = new ServiceHost(typeof(CalculatorService),
new Uri[] { new Uri("net.pipe://localhost/PINSenderService") });
_host.AddServiceEndpoint(typeof(ICalculator),
new NetNamedPipeBinding(),
"");
_host.Open();
ChannelFactory<ICalculator> factory = new ChannelFactory<ICalculator>(
new NetNamedPipeBinding(NetNamedPipeSecurityMode.None),
new EndpointAddress("net.pipe://localhost/PINSenderService"));
ICalculator proxy = factory.CreateChannel();
proxy.SendPin(pin);
((IClientChannel)proxy).Close();
factory.Close();
Run Code Online (Sandbox Code Playgroud)
自托管WCF服务
namespace PINSender
{
// Define a service contract.
public interface ICalculator
{
[OperationContract]
void SendPin(string pin);
}
// Implement the ICalculator service contract in a service class.
public class CalculatorService : ICalculator
{
// Implement the ICalculator methods.
public void SendPin(string pin)
{
} …Run Code Online (Sandbox Code Playgroud) 我有一个Task查询活动目录并用结果填充列表的方法。我已经设置了我的任务,以便可以取消它,但是,当调用取消时,任务将继续执行其工作。我知道任务已被取消,因为它返回并且打算在任务返回时执行的操作正在运行,但查询继续在后台运行,使用内存和处理能力。任务可以重复启动和“取消”,任务的每次迭代都会运行并使用资源。我怎样才能让取消真正取消?
private async Task RunQuery(QueryType queryType,
string selectedItemDistinguishedName = null)
{
StartTask();
try
{
_activeDirectoryQuery = new ActiveDirectoryQuery(queryType,
CurrentScope, selectedItemDistinguishedName);
await _activeDirectoryQuery.Execute();
Data = _activeDirectoryQuery.Data.ToDataTable().AsDataView();
CurrentQueryType = queryType;
}
catch (ArgumentNullException)
{
ShowMessage(
"No results of desired type found in selected context.");
}
catch (OutOfMemoryException)
{
ShowMessage("The selected query is too large to run.");
}
FinishTask();
}
private void CancelCommandExecute()
{
_activeDirectoryQuery?.Cancel();
}
Run Code Online (Sandbox Code Playgroud)
public async Task Execute()
{
_cancellationTokenSource = new CancellationTokenSource();
var taskCompletionSource = new …Run Code Online (Sandbox Code Playgroud) 我只有一个同步操作,可能需要很多时间才能完成。该操作的调用者提供了一个CancellationToken符号,并且在令牌被取消后,该操作应立即停止(在这种情况下,取消后的几毫秒内也将起作用)。
如何将其包装在带有CancellationToken的任务中?
我无法更改调用代码或调用本身。
曾经是: LongOperation();
我现在所拥有的: await Task.Run(() => LongOperation(), cancellationToken).ConfigureAwait(false);
显然,这是行不通的,因为您必须在给的操作中轮询令牌Task.Run。