我有一个自托管的wcf双工回调服务的问题.我得到一条InvalidOperationException消息:
此操作将死锁,因为在当前消息完成处理之前无法接收回复.如果要允许无序消息处理,请在CallbackBehaviorAttribute上指定Remediate的ConcurrencyMode或Multiple.
这是我的服务行为:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Reentrant, UseSynchronizationContext = true)]
Run Code Online (Sandbox Code Playgroud)
这是我的服务合同:
[ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(IClientCallback))]
[ServiceContract]
public interface IClientToService
{
[OperationContract(IsOneWay = false)]
LVSSStatus GetLvssStatus();
[OperationContract(IsOneWay = true)]
void PickSpecimen(long trackingNumber, int destCode);
[OperationContract(IsOneWay = true)]
void CancelCurrentPickTransaction();
}
Run Code Online (Sandbox Code Playgroud)
这是我的回调界面:
public interface ILvssClientCallback
{
[OperationContract(IsOneWay = true)]
void SendClientCallback(LvssCallbackMessage callbackMessage);
[OperationContract(IsOneWay = false)]
List<SpecimenTemplateDescriptor> GetTemplateDescriptorList(DrawerLayout drawerLayout);
[OperationContract(IsOneWay = false)]
SpecimenTemplate SelectSpecimenTemplate(string templateName, int version);
[OperationContract]
void SpecimenStoredInContainer(string containerID, bool isValidRackID, int rackRow, int rackCol, …Run Code Online (Sandbox Code Playgroud) 我有一段时间搞清楚如何处理来自ViewModel之外的类的Thread.
Thread来自一个Track类.这是以下ResponseEventHandler代码Track:
public delegate void ResponseEventHandler(AbstractResponse response);
public event ResponseEventHandler OnResponseEvent;
Run Code Online (Sandbox Code Playgroud)
当从我的Track对象中处理"命令"方法时,以下代码运行OnResponseEvent,它将线程中的消息发送回我的ViewModel:
if (OnResponseEvent != null)
{
OnResponseEvent(GetResponseFromCurrentBuffer());
}
Run Code Online (Sandbox Code Playgroud)
GetResponseFromCurrentBuffer()只返回一个消息类型,它是一个预定义的类型Track.
我的MainWindowViewModel构造函数创建了一个事件处理程序OnResponseEvent从Track:
public MainWindowViewModel()
{
Track _Track = new Track();
_Track.OnResponseEvent +=
new Track.ResponseEventHandler(UpdateTrackResponseWindow);
}
Run Code Online (Sandbox Code Playgroud)
所以,我的想法是每次有来自OnResponseEventThread的新消息时,我都会运行该UpdateTrackResponseWindow()方法.此方法将新的消息字符串附加到ObservableCollection<string>名为的列表属性TrackResponseMessage:
private void UpdateTrackResponseWindow(AbstractResponse message)
{
TrackResponseMessage.Add(FormatMessageResponseToString(message));
}
Run Code Online (Sandbox Code Playgroud)
该FormatMessageResponseToString()方法仅将消息与其中的所有预定义消息类型进行比较Track,并进行一些漂亮的字符串格式化.
主要问题是: 运行时UI消失TrackResponseMessage.Add().可执行文件仍在后台运行,结束任务的唯一方法是关闭Visual Studio …
我有一个绑定到ObservableCollection的ListView ItemsSource.我通过MVVM添加了一个属性来跟踪ListView.SelectedItem.我的ListView中添加了一个按钮(通过GridViewColumn.CellTemplate)来创建一个按钮命令,该命令显示有关我的ObservableCollection中每个对象的数据.因此,我的ObservableCollection(ListView列1)中的对象列表显示在ListView中,带有相应的按钮(ListView列2).
守则很棒!唯一的问题是:在单击列表中的相应按钮之前,用户必须单击ListView行.(如果用户单击按钮而不先单击ListView行,我的"SelectedFromQueue"属性会出现空引用异常.)
我想添加代码,单击按钮时设置ListView.SelectedItem属性.因此,如果用户单击按钮,则代码应在执行关联的MVVM命令之前更新ListView.SelectedItem属性绑定.
有人有任何示例代码吗?谢谢你的帮助.
我的XAML:
<UserControl xmlns:local="clr-namespace:MyApp"
x:Class="MyApp.QueueObjectList"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" Height="290" Width="320">
<Grid Width="319">
<GroupBox Header="Queue Class List" HorizontalAlignment="Left" Width="319" BorderBrush="Black" BorderThickness="2">
<ListView ItemsSource="{Binding Path=QueueList}" Name="QueueListView">
<ListView.SelectedItem>
<Binding Path="SelectedFromQueue" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
</Binding>
</ListView.SelectedItem>
<ListView.View>
<GridView>
<GridViewColumn Width="140" Header="Queue Name" DisplayMemberBinding="{Binding Name}" />
<GridViewColumn Width="179" Header="Property Information">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Content="Get Property Info" Command="{Binding Path=GetQueueObjProperties}"
DataContext="{Binding DataContext, RelativeSource={RelativeSource FindAncestor, AncestorType=ListView}}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</GroupBox>
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
我的MainWindowViewModel C#代码:
private ObservableCollection<Queue> _QueueList;
private Queue …Run Code Online (Sandbox Code Playgroud) 我创建了一个标准的NServiceBus发布订阅程序。向发布者NServicBus主机发送消息时,我始终收到以下错误:
没有为消息TrackEventPublisher.TrackEventPublisher.InternalMessages.TrackEventMessages指定目的地。消息无法发送。检查配置文件中的UnicastBusConfig部分,并确保消息类型存在MessageEndpointMapping。
好吧...。MessageEndpointMapping存在!
这是我用来测试MessagePublisher类的测试控制台应用程序代码:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Click enter to submit message.");
Console.ReadLine();
string aMessage = "Please Work!!!!!!!!";
MessagePublisher publisher = new MessagePublisher();
publisher.PublishEventMessage(aMessage);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的消息发送者类,它将消息发送到另一个要发布的NServiceBus发布服务器:
public class MessagePublisher
{
public IBus Bus { get; set; }
public MessagePublisher()
{
BusInitializer.Init();
Bus = BusInitializer.Bus;
}
public void PublishEventMessage(string message)
{
Bus.Send(new TrackEventMessages(message));
}
}
Run Code Online (Sandbox Code Playgroud)
我的总线初始化程序:
class BusInitializer
{
public static IBus Bus { get; private set; }
public static void Init()
{
Bus = …Run Code Online (Sandbox Code Playgroud)