我有一个用C#编写的WCF服务托管在远程机器上,作为本地管理员帐户运行.从我作为活动目录用户登录的计算机,我发送的命令只是告诉它在网络上打开一个文件.我有权访问该文件,但主机上的管理员帐户却没有.我在需要模拟的方法上使用[OperationBehavior(Impersonation = ImpersonationOption.Required)]元标记,并且我正确设置了凭据类型和安全模式.我可以通过比较Windows身份来验证帐户确实是在冒充,但我仍然会获得访问被拒绝的异常.我认为这与活动目录有关,而不是对模拟用户进行身份验证.有什么我想念的吗?
我有一台运行单个程序的计算机,可以在另外4台计算机上管理多达48个单独的进程.我有这样设置的WCF服务(每个进程一个):
public void StartService(Uri uri, string identifier)
{
unitMetaData = identifier;
var binding = new WSDualHttpBinding(WSDualHttpSecurityMode.None);
binding.ReliableSession.InactivityTimeout = TimeSpan.FromDays(20);
var reader = binding.ReaderQuotas as XmlDictionaryReaderQuotas;
reader.MaxStringContentLength = WCFContentSize; // 16777216
service = new ServiceHost(this, uri);
service.Faulted += TestService_Faulted;
service.AddServiceEndpoint(
typeof(IController),
binding,
identifier);
service.Open();
}
Run Code Online (Sandbox Code Playgroud)
以下是远程进程的代码:
public void Connect()
{
// External binding used to change the WCF XML text content size
var binding = new WSDualHttpBinding(WSDualHttpSecurityMode.None);
binding.ReliableSession.InactivityTimeout = TimeSpan.FromDays(20);
var reader = binding.ReaderQuotas as XmlDictionaryReaderQuotas;
reader.MaxStringContentLength = WCFContentSize; // 16777216 …Run Code Online (Sandbox Code Playgroud) 我有一个使用ItemsSource绑定到集合的上下文菜单:
<Button Content="Submit">
<Button.ContextMenu>
<ContextMenu Name="SubmitButtonContextMenu" ItemsSource="{Binding MyDataSource}">
<ContextMenu.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}">
<!-- Setters -->
</Style>
</ContextMenu.ItemContainerStyle>
</ContextMenu>
</Button.ContextMenu>
</Button>
Run Code Online (Sandbox Code Playgroud)
它目前会显示如下: 菜单项
基本上,我想添加两个静态项:另一个永不改变的MenuItem,以及一个用于分隔我的静态内容和动态内容的spacer.我可以把我的收藏装到这个数据中,但我觉得应该有一个更优雅的解决方案.我也希望避免使用子上下文菜单.
编辑:这是我最终实现的:
<Window ...>
<Window.Resources>
<s:SubmitItemStyleSelector x:Key="SubmitItemStyleSelector">
<s:SubmitItemStyleSelector.SubmitButtonStyle>
<Style TargetType="MenuItem">
<!--Setters-->
</Style>
</s:SubmitItemStyleSelector.SubmitButtonStyle>
</s:SubmitItemStyleSelector>
<CollectionViewSource x:Key="MyDataViewSource" Source="{Binding MyDataSource}"/>
</Window.Resources>
...
<Button Content="Submit">
<Button.ContextMenu>
<ContextMenu ItemContainerStyleSelector="{Binding Source={StaticResource SubmitItemStyleSelector}}">
<ContextMenu.ItemsSource>
<CompositeCollection>
<MenuItem Header="No Change"/>
<Separator/>
<CollectionContainer Collection="{Binding Source={StaticResource MyDataViewSource}}"/>
</CompositeCollection>
</ContextMenu.ItemsSource>
</ContextMenu>
</Button.ContextMenu>
</Button>
Run Code Online (Sandbox Code Playgroud)
然后我的SubmitItemStyleSelector从MyDataSource中找到我想要的类型,仅对这些项目进行额外的样式设置.
我知道标题可能很难理解,很难想到一个合适的标题,但这是我想要做的事情的本质.
基本上我想要一个像这样的方法:
void Validate(bool validation)
{
if (!validation)
{
throw new Exception();
}
}
Run Code Online (Sandbox Code Playgroud)
然后我想把它称为:
try
{
Validate(1 > 2);
}
catch (Exception e)
{
// This is where I would output the error to the user
}
Run Code Online (Sandbox Code Playgroud)
我希望将该1 > 2部分作为字符串获取而不将其定义为其他地方,或者将字符串评估为a bool,或使用谓词或使用外部方法.理想情况下,这将通过反射来完成.我还会就更好的方式做我想做的事情.假设bool可以是任何东西:1 > 2,"cheese" != "ham",objectA == objectB等.
在过去7个月左右的时间里,我几乎专门用.NET C#进行编程.在此之前,我的大部分编程都是使用C++(来自学校).在工作中,我可能需要在接下来的几个月内完成一大堆C语言.我接触C的大部分内容都来自微控制器以及我在互联网上找到的东西.我理解C和C++之间的语法和许多区别,但我不知道存在什么类型的内置函数,我需要利用哪些库来使用所述函数,以及一些内存管理问题.基本上我需要在C上找到某种快速速成课程.建议?