我有一个使用HttpBinding的WCF服务.该服务在自托管进程(Windows服务)中运行,此过程位于Windows防火墙例外列表中.
如果防火墙处于活动状态且我尝试使用C#客户端或Internet Explorer访问该服务,则该服务不会响应.但是,如果禁用防火墙,则连接就像魅力一样.
有没有人有WCF和Windows防火墙的过期?问题出现在Windows 7 64位上.我还没有尝试过其他操作系统.
我应该做些什么来使用活动防火墙?
关心迈克尔
编辑:我发现一个线索,http.sys必须添加到防火墙例外列表,因为wcf自托管使用http.sys.有什么建议,如何解决?
编辑:我试图手动打开所有的监听端口,这也有效,但不是一个选项,因为我事先不知道它们.
我正在尝试使用64位进程读取Excel电子表格.因此,我使用64位版本的Micorosft Access数据库引擎2010.
以下代码
var cs = @"Provider=Microsoft.ACE.OLEDB.12.0;"
+ @"Data Source=C:\test.xls;"
+ @"Extended Properties=""Excel 14.0;""");
con = new OleDbConnection(cs);
con.Open();
Run Code Online (Sandbox Code Playgroud)
抛出异常:
找不到可安装的ISAM
使用谷歌我发现了很多关于这个例外的问题.但他们提到JET并且似乎不适用于我的问题.
有什么建议?
我正在实现一个实现 IDictionary 的类。但我无法匹配 TryGetValue 的代码合同。
这是代码的相关部分:
class Wrapper : IDictionary<string, object>
{
...
IDictionary<string,object> dictionary;
public bool TryGetValue(string key, out object value)
{
var result = dictionary.TryGetValue(key, out value);
Contract.Assume(result == ContainsKey(key));
return result;
}
public bool ContainsKey(string key)
{
Contract.Ensures(Contract.Result<bool>() == dictionary.ContainsKey(key));
return dictionary.ContainsKey(key);
}
...
}
Run Code Online (Sandbox Code Playgroud)
静态分析抱怨:
CodeContracts:确保未经证实:
Contract.Result<bool>() == @this.ContainsKey(key)
我应该怎样做才能满足合同要求?
备注:当密钥是通用的(如 )时,不会出现该问题Wrapper<TKey> : IDictionary<TKey, object>
。
我对Xaml很新,需要一些建议.
TreeView应绑定到分层对象结构.TreeView应该有一个上下文菜单,该菜单特定于每个对象类型.
我尝试过以下方法:
<TreeView>
<TreeView.Resources>
<DataTemplate x:Key="RoomTemplate">
<TreeViewItem Header="{Binding Name}">
<TreeViewItem.ContextMenu>
<ContextMenu>
<MenuItem Header="Open" />
<MenuItem Header="Remove" />
</ContextMenu>
</TreeViewItem.ContextMenu>
</TreeViewItem>
</DataTemplate>
</TreeView.Resources>
<TreeViewItem Header="{Binding Name}" Name="tviRoot" IsExpanded="True" >
<TreeViewItem Header="Rooms"
ItemsSource="{Binding Rooms}"
ItemTemplate="{StaticResource RoomTemplate}">
<TreeViewItem.ContextMenu>
<ContextMenu>
<MenuItem Header="Add room"></MenuItem>
</ContextMenu>
</TreeViewItem.ContextMenu>
</TreeViewItem>
</TreeViewItem>
Run Code Online (Sandbox Code Playgroud)
但是使用此标记时,行为符合预期,但子项(房间)缩进太多.
无论如何,我能找到的所有结果样本都在DataTemplate中使用TextBlock而不是TreeViewItem,但是想知道如何在那里集成ContextMenu.
考虑以下数据结构:
List<Person> People;
class Person {
List<Car> Cars;
List<Hobby> Hobbies;
}
Run Code Online (Sandbox Code Playgroud)
我想将TreeView绑定到此结构.它看起来应该是这样的:
People
> Frank
> Cars
> BMW
> Ford
> Hobbies
> Tennis
> Golf
> Jane
> Cars
> Hobbies
Run Code Online (Sandbox Code Playgroud)
如何在XAML中实现这一目标?这是我到目前为止所得到的:
<TreeView>
<TreeView.Resources>
<DataTemplate x:Key="PersonTemplate">
<TextBlock Header="{Binding Name}">
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem Header="Remove" />
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</DataTemplate>
</TreeView.Resources>
<TreeViewItem Header="{Binding Name}"IsExpanded="True" >
<TreeViewItem Header="People"
ItemsSource="{Binding People}"
ItemTemplate="{StaticResource PersonTemplate}">
</TreeViewItem>
</TreeViewItem>
</TreeView>
Run Code Online (Sandbox Code Playgroud)
我有一个ViewModel集合,并希望将ListBox绑定到它们.做了一些调查我发现了这个.
所以我的ViewModel看起来像这样(伪代码)
interface IItemViewModel
{
string DisplayName { get; }
}
class AViewModel : IItemViewModel
{
string DisplayName { return "foo"; }
}
class BViewModel : IItemViewModel
{
string DisplayName { return "foo"; }
}
class ParentViewModel
{
IEnumerable<IItemViewModel> Items
{
get
{
return new IItemViewModel[] {
new AItemViewModel(),
new BItemViewModel()
}
}
}
}
class GroupViewModel
{
static readonly GroupViewModel GroupA = new GroupViewModel(0);
static readonly GroupViewModel GroupB = new GroupViewModel(1);
int GroupIndex;
GroupViewModel(int groupIndex)
{
this.GroupIndex …
Run Code Online (Sandbox Code Playgroud) 我想禁用屏幕保护程序并关闭电源.在这个阶段,没有窗户形式,我可以.因此,我不想使用NativeWindow.
这是我的代码
sealed class ObserverWindow : NativeWindow, IDisposable
{
internal ObserverWindow()
{
this.CreateHandle(new CreateParams()
{
Parent= IntPtr.Zero
});
}
public void Dispose()
{
DestroyHandle();
}
protected override void WndProc(ref Message msg)
{
if (msg.Msg == WM_SYSCOMMAND &&
((((long)msg.WParam & 0xFFF0) == SC_SCREENSAVE) ||
((long)msg.WParam & 0xFFF0) == SC_MONITORPOWER))
{
msg.Msg = 0;
msg.HWnd = IntPtr.Zero;
}
base.WndProc(ref msg);
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,没有使用WM_SYSCOMMAND调用WndProc.实际上,WndProc被称为4次.在最后一次调用时,有msg.Msg == WM_CREATE.
我想我错过了一些创建参数.有人有建议吗?
关心迈克尔
UPDATE
我在非STA线程中运行代码.因此,窗口没有显示任何消息,而不是初始消息.现在我收到了WM_SYSCOMMAND消息.但是当屏幕保护程序激活时,没有消息.
我也尝试用相同的结果覆盖Form的WndProc.但这曾经在Windows XP中运行.Windows 7有变化吗?
操作系统:Windows 7 64位.
解
正如本问题中的评论所述,只有前景窗口可以取消屏幕保护程序.因此上面的代码无法工作.NativeWindow非常适合接收消息,但不适用于取消屏幕保护程序.对于后者,我推荐这个问题的答案.