我有一个使用自定义的WCF服务ServiceAuthorizationManager.自定义身份验证管理器已设置为处理Windows和Forms身份验证.
但是,如果我连接到设置为UserNameauth 的客户端,我似乎无法在任何地方找到用户名.
客户端代码如下所示:
this.ClientCredentials.UserName.UserName = "user";
this.ClientCredentials.UserName.Password = "pass";
this.Open();
this.MyMethod(); // my actual contract method
this.Close();
Run Code Online (Sandbox Code Playgroud)
然后在服务器上,我有我的自定义身份验证管理器:
public sealed class AppAuthorizationManager : ServiceAuthorizationManager
{
public override bool CheckAccess(OperationContext operationContext, ref Message message)
{
// would like to check user/pwd here...
}
}
Run Code Online (Sandbox Code Playgroud)
这可能吗?
Thread.CurrentPrincipal未设置,operationContext.ServiceSecurityContext.PrimaryIdentity 没有设定.operationContext.ServiceSecurityContext.AuthorizationContext.ClaimSets 是空的. 用户/密码应该在任何地方可用吗?或者我是否还要添加自定义UsernamePasswordValidator?
更新:所以我添加了一个自定义UserNamePasswordValidator和一个IAuthorizationPolicy.我更新的WCF配置如下所示:
<behavior name="Server2ServerBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceAuthorization principalPermissionMode="Custom" serviceAuthorizationManagerType="MyApp.AuthManager, MyApp">
<authorizationPolicies>
<add policyType="MyApp.TokenAuthorizationPolicy, …Run Code Online (Sandbox Code Playgroud) 我有一种情况,我在一个具有TransactionScopeRequired = true的WCF服务中运行,这意味着将始终存在环境事务.
但是,我需要在应用程序的生命周期内启动一个新的连接,这意味着我不能让它使用abmbient事务.
关于如何做到这一点的任何想法?这样做会自动使用环境事务:
Assert.IsNotNull(System.Transactions.Transaction.Current);
var conn = new OracleConnection("my connection string");
conn.Open(); // <-- picks up ambient transaction, but I don't want that
Run Code Online (Sandbox Code Playgroud)
实际上这个例子可以通过这样说来变得更简单:
OracleConnection conn; // <-- this is actually held around in another object that has a very long lifetime, well past the TransactionScope.
using(var tx = new TransactionScope())
{
conn = new OracleConnection("my connection string");
conn.Open(); // <-- picks up ambient transaction, but I don't want that
// ... do stuff
}
Run Code Online (Sandbox Code Playgroud)
我不希望我的连接真正拿起TransactionScope.在实际代码中,还有很多事情要做,范围内的数据库操作,我只需要1,我需要在事务范围的生命周期内保持不变.
我想真实的情况值得一提.这里实际发生的是在WCF服务调用期间,我使用企业库缓存块将对象添加到缓存.此对象是一个数据表,但也保持与Oracle建立连续通知的开放连接.这使我能够在底层Oracle表更改时自动刷新缓存的数据集.
任何数量的WCF初始化线程都可以访问数据缓存项,所有这些线程都在自己的事务范围内运行.我想你可以把它想象成将一个OracleConnection对象放在缓存中.更好的文本/示例代码块将是: …
我有一个现有的WCF服务.在某些时候,有时一个[OperationContract]或[DataMember]一个数据合同变成了[Obsolete].出于兼容性的原因,我不想删除该方法.另一个例子是有时我有一个Enum,并且想要[Obsolete]其中一个选项,但是我无法完全删除它,因为系统/数据库中已存在包含该值的项.
无论如何,有没有办法从生成的WDSL中省略某些项目?例如:
[ServiceContract]
public interface IMyService
{
[OperationContract]
string SomeMethod(string x); // I do want this in the WSDL
[Obsolete]
[OperationContract]
string OldMethod(string x); // I do NOT want this in the WSDL, but I do want it to still work / be callable if an older system tries to call it.
}
Run Code Online (Sandbox Code Playgroud) PHP中是否有一种方法可以包含或执行单独文件中的代码?
例如,如果我们有2个文件:
a.php包含:
<?php echo "i'm a.php"; ?>
Run Code Online (Sandbox Code Playgroud)
和b.php包含:
<?php
echo "i'm b.php";
// some code here to "execute" a.php so that it prints i'm a.php as the output.
?>
Run Code Online (Sandbox Code Playgroud)
当b.php运行时,它应显示:
i'm b.php
i'm a.php
Run Code Online (Sandbox Code Playgroud) 这真的让我今天难过.我确定它很简单,但是......这是我的示例代码:
using System;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
public ArrayList SomeProp { get; set; }
static void Main(string[] args)
{
// Get the Type of a property by reflection.
Type myPropType = typeof(Program).GetProperty("SomeProp").PropertyType;
// Create an instance of the determined Type.
var x = Activator.CreateInstance(myPropType);
// Now try to use that instance, passing to a method that takes a generic.
WhatAmI(x);
Console.ReadKey();
}
private static void WhatAmI<T>(T x)
{
Console.WriteLine("T is: " + typeof(T).FullName);
Console.WriteLine("x is: " …Run Code Online (Sandbox Code Playgroud) 我试图从数据表对象中提取值并动态填充对象以进行webservice调用,我已经尝试了一些方法但是将它们缩小到这个,它似乎缺少的是能够反映目标类型并转换为对象从数据表变为一个.
我在这里摸不着头脑!
foreach (PropertyInfo pi in zAccount)
{
object o = row[pi.Name];
if (o.GetType() != typeof(DBNull))
{
pi.SetValue(a, o, null);
}
}
Run Code Online (Sandbox Code Playgroud)
这给了我类型转换错误:
"System.String"类型的对象无法转换为"System.Nullable .1 [System.Boolean]"类型.
所以理想的是这样的:
foreach (PropertyInfo pi in zAccount)
{
object o = typeof(pi.GetType())row[pi.Name];
pi.SetValue(a, o, null);
}
Run Code Online (Sandbox Code Playgroud) 我的老师已经指示我在编写指令0之前追加,hexa numbers因为一些编译器会0在指令编号之前搜索,以区别于标签.如果指令已经以0开头,我很困惑,在这种情况下该怎么办?
例如,
AND BL, 0FH
Run Code Online (Sandbox Code Playgroud)
是否需要0在该六进制数之前添加?请帮帮我.谢谢
对不起,如果我以前不够清楚.我的意思是,在上面的例子中,0已经存在,我是否需要将其转换为,
AND BL, 00FH
Run Code Online (Sandbox Code Playgroud) WCF数据服务根据Accept:标头更改其响应JSON格式,因此这两个标头提供不同的结果:
Accept: application/json
Accept: application/json; odata=verbose
Run Code Online (Sandbox Code Playgroud)
但是,OData规范提供了$format=应该执行相同操作的查询参数.WCF似乎尊重$format=json参数,但将其视为application/json接受标头.但我想要详细的JSON ......
所以我的问题是; 有什么可能的价值$format=?有没有办法使用它来指定详细的JSON?
(我已经知道我可以更改我的代码以使用accept标头,但现有代码使用$ format,所以我更愿意改变它.)
我正在使用预发布的WCF数据服务,v5.1.0-rc2
编辑:
我的请求看起来像这样:
网址:
http://localhost:52116/Services/MusicStore.svc/Albums?$format=json&%24inlinecount=allpages&%24filter=substringof('the'%2Ctolower(Title))
Run Code Online (Sandbox Code Playgroud)
请求标题:
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
DataServiceVersion: 3.0
Host: localhost:52116
MaxDataServiceVersion: 3.0
MinDataServiceVersion: 3.0
Proxy-Connection: keep-alive
Referer: http://localhost:52116/
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4
X-Requested-With: XMLHttpRequest
Run Code Online (Sandbox Code Playgroud)
这将返回有效的JSON(非详细).
但是,如果我尝试,$format=jsonverbose那么我从WCF获得HTTP 500,在跟踪日志中有这个:
<Exception>
<ExceptionType>System.ServiceModel.CommunicationObjectAbortedException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>The communication object, System.ServiceModel.Channels.TransportReplyChannelAcceptor+TransportReplyChannel, cannot be used for communication …Run Code Online (Sandbox Code Playgroud)