我有一个我在WebApplication中创建的WCF服务,在web.config中具有以下配置
<service name="RedwebServerManager.WebApplication.DesktopService"
behaviorConfiguration="ServBehave">
<endpoint
address=""
binding="basicHttpBinding"
bindingConfiguration="basicBind"
contract="RedwebServerManager.WebApplication.IDesktopService"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="basicBind">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Windows"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)
此服务需要接收WindowsCredentials以根据经过身份验证的用户获取数据库中的信息.此服务当前有一种方法实现具有以下签名的接口
[ServiceContract]
public interface IDesktopService
{
/// <summary>
/// Gets the clients.
/// </summary>
/// <returns>IEnumerable<ClientServiceModel>.</returns>
[OperationContract]
IEnumerable<ClientServiceModel> GetClients();
}
Run Code Online (Sandbox Code Playgroud)
我有一个Windows窗体应用程序正在使用WCF服务,我想使用应用程序传递当前用户的凭据,因为这将全部位于我们的域上.app.config如下
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IDesktopService">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Windows" proxyCredentialType="Windows"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://redwebservermanager.redweb.network/DesktopService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDesktopService"
contract="ManagerService.IDesktopService" name="BasicHttpBinding_IDesktopService" />
</client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
如果我手动设置凭据用户名和密码一切正常,但我一直在尝试
managerService.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials
Run Code Online (Sandbox Code Playgroud)
这样我就可以传递当前用户的凭据,但是在调用GetClients()时,我一直收到错误,即没有设置用户名和密码.
谁能帮我?我也尝试过添加
[OperationBehavior(Impersonation = ImpersonationOption.Required)]
Run Code Online (Sandbox Code Playgroud)
方法,但这没有任何区别.
我有一个名为Category的实体,实体包含一个名为ChildCategories的IEnumerable.类别可以具有这些子类别,这些子类别可以具有其自己的子类别等等.
假设我选择了顶级父类别,我想获得所有子类别及其子类别等等,以便我拥有该类别的所有层次结构子级.我希望这个奉承并返回初始类别.我尝试过创造类似的东西
public static IEnumerable<T> AllChildren<T>(this IEnumerable<T> items,
Func<T, IEnumerable<T>> children, bool includeSelf)
{
foreach (var item in items)
{
if (includeSelf)
{
yield return item;
}
if (children != null)
{
foreach (var a in children(item))
{
yield return a;
children(a).AllChildren(children, false);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在使用SelectMany方法之后哪个会变得扁平,但是还没有得到它.
我正在创建一些需要会话感知的 WEB API 2 控制器。我以前通过添加来做到这一点
/// <summary>
/// Application_s the post authorize request.
/// </summary>
protected void Application_PostAuthorizeRequest()
{
HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required);
}
Run Code Online (Sandbox Code Playgroud)
但是,我们在站点的其他业务关键部分的解决方案中有 API 控制器,这些控制器已经过高度优化,返回大约 500 毫秒的响应,如果打开它,它会持续长达 2 秒。这些控制器不需要会话感知。
我们只需要提供会话访问权限的某些控制器,我已经阅读了这篇文章http://www.codeproject.com/Tips/513522/Providing-session-state-in-ASP-NET-WebAPI并且正在考虑是否可以添加具有会话意识的不同路由,但在映射路由时没有RouteHandler属性。
有没有人有任何想法?