我可以使用AWS身份验证来保护我的WCF服务吗?我想通过谷歌搜索找出这一点,并找到有关使用AWS身份验证调用已经安全的服务的文章.不是关于如何使用AWS保护WCF服务的文章.是不是有一个选项,是我对AWS身份验证的理解和签署错误的.请指点我开头的文章.
我有这个简单的课程
public class Program
{
private static void Main(string[] args)
{
ClassB<ClassA> objA = new ClassB<ClassA>();
ClassB<ITestA<MyDTO>> objB = new ClassB<ClassA>();
}
}
public class ClassB<T>
{
///some code here
}
public interface ITestA<T>
{
///some code here
}
public class MyDTO
{
///some code here
}
public class ClassA : ITestA<MyDTO>
{
///some code
}
Run Code Online (Sandbox Code Playgroud)
这行代码
ClassB<ITestA<MyDTO>> objB = new ClassB<ClassA>();
Run Code Online (Sandbox Code Playgroud)
给出编译错误
Cannot implicitly convert type 'ClassB<ClassA>' to 'ClassB<ITestA<MyDTO>>
Run Code Online (Sandbox Code Playgroud)
由于 ClassA 实现了 ITestA,我不知道为什么会出现编译错误。请帮助我理解我做错了什么。
谢谢,埃森
我正在尝试编写一个通用函数,它将 datagridview 的数据源转换为列表(然后我想向列表中添加一个空对象。数据源可以是任何类型)?
我的一些绝望尝试是这样的:
Type datagrid_type = dgv.DataSource.GetType();
List<object> the_source = dgv.DataSource as List<object>;
Convert.ChangeType(the_source, datagrid_type);
Object c = Activator.CreateInstance(datagrid_type);
Convert.ChangeType(c, datagrid_type);
the_source.Add(c);
Run Code Online (Sandbox Code Playgroud)
..butthe_source
只是空的。即使不是,它仍然可能无法正常工作。我相信你们会有更聪明的方法(一个真正有效的方法..)来实现这一目标。
ps 我正在使用 EF 创建一个列表,它是数据源,因此将数据源转换为 DataTable 可能与此处无关
我有一个sql服务器(server1)和webservice服务器(server2)。server2具有以下代码。它从客户端获取结果请求并更新数据库。
try
{
AppLogger.DebugFormat("Entered into save result - [{0}]", result.ID);
int retry = 0;
while (++retry <= 5)
{
try
{
using (var oConnection = new SqlConnection("Connection string"))
{
oConnection.Open();
AppLogger.Debug("Saving data into db");
oConnection.Execute("storedproc1", new
{
param1 = Convert.ToInt32(result.value1),
param2 = Convert.ToInt32(result.value2),
param3 = result.value3=="Success",
param4 = result.vaue4
}, commandType: CommandType.StoredProcedure);
AppLogger.DebugFormat("Save done with [{0}] try", retry);
break;
}
}
catch (SqlException sx)
{
if (retry == 5)
{
AppLogger.Debug("sql exception occured");
throw;
}
else
{
AppLogger.ErrorFormat("Exception occurred [{0}] …
Run Code Online (Sandbox Code Playgroud) 请参考以下脚本
declare @table1 table
(
col1 int
)
declare @table2 table
(
col2 int
)
insert into @table1 values(1)
insert into @table1 values(2)
insert into @table1 values(3)
insert into @table1 values(5)
insert into @table1 values(7)
insert into @table2 values(1)
insert into @table2 values(3)
insert into @table2 values(3)
insert into @table2 values(6)
insert into @table2 values(4)
insert into @table2 values(7)
Run Code Online (Sandbox Code Playgroud)
情况1:
select * from @table1 a left outer join @table2 b on a.col1=b.col2
order by col1
Run Code Online (Sandbox Code Playgroud)
结果 1:
col1 col2
----------- …
Run Code Online (Sandbox Code Playgroud) 我正在使用dnsdynamic.org指向我家中托管的个人网站.我家的ip会经常每月更换一次.dnsdynamic.org提供了一个更新ip的web方法调用.
https://username:password@www.dnsdynamic.org/api/?hostname=techno.ns360.info&myip=127.0.0.1
Run Code Online (Sandbox Code Playgroud)
当我通过浏览器调用它时,它完美无缺.当我尝试通过c#代码调用它时,它会抛出以下异常.
Invalid URI: Invalid port specified.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Net.WebRequest.Create(String requestUriString)
Run Code Online (Sandbox Code Playgroud)
由于url中有冒号,因此看起来system.uri尝试将我的密码解析为整数.
我尝试在.org之后添加一个端口
https://username:password@www.dnsdynamic.org:443
Run Code Online (Sandbox Code Playgroud)
没有运气.
有人可以指点我如何解决这个错误.
我在创建uri时尝试了不要逃避和逃避选项,仍然无法正常工作.
var ri = new Uri("https://username:password@www.dnsdynamic.org/api/?hostname=techno.ns360.info&myip=127.0.0.1",true);
Run Code Online (Sandbox Code Playgroud)
编辑:看起来用户名导致问题.我的用户名是我的电子邮件地址 我的电子邮件地址以*.com结尾.所以uri试图解析我的密码.
仍未找到解决此问题的解决方案.我无法更改用户名,因为dnsdyanmic.org使用电子邮件地址作为用户名.
我试图得到一个没有聚合的枢轴结果,我试过max并没有帮助,可能是我做错了.
当我运行以下查询时
declare @t table
(
col1 int,
col2 varchar(100),
col3 varchar(100),
col4 varchar(100),
col5 int
)
insert into @t values(1,'test1','p1','v1',1)
insert into @t values(1,'test1','p2','v2',2)
insert into @t values(1, 'test1','p3','v3',3)
insert into @t values(1,'test1','p1','v11',1)
insert into @t values(1,'test1','p1','v12',1)
insert into @t values(1,'test1','p2','v21',2)
insert into @t values(1,'test1','p2','v22',2)
--select * from @t
select col1,
col2,
[p1],
[p2],
[p3]
from
(
select * from @t
) x
pivot
(
Max(col4 )
for col3 in ([p1],[p2],[p3])
) pvt
Run Code Online (Sandbox Code Playgroud)
我得到以下结果
我试图得到以下结果
如果你能告诉我实现这一目标的途径,那就太好了.
我正在使用PostgreSQL为C#桌面应用程序提供支持.当我使用PgAdmin查询分析器更新具有特殊字符的文本列(如版权商标)时,它可以很好地工作:
update table1 set column1='value with special character ©' where column2=1
Run Code Online (Sandbox Code Playgroud)
当我从我的C#应用程序使用相同的查询时,它会抛出一个错误:
用于编码的无效字节序列
在研究了这个问题之后,我理解.NET字符串使用UTF-16 Unicode编码.
考虑:
string sourcetext = "value with special character ©";
// Convert a string to utf-8 bytes.
byte[] utf8Bytes = System.Text.Encoding.UTF8.GetBytes(sourcetext);
// Convert utf-8 bytes to a string.
string desttext = System.Text.Encoding.UTF8.GetString(utf8Bytes);
Run Code Online (Sandbox Code Playgroud)
这里的问题是sourcetext
和desttext
编码为UTF-16字符串.当我通过时desttext
,我仍然得到例外.
我也试过以下没有成功:
Encoder.GetString, BitConverter.GetString
Run Code Online (Sandbox Code Playgroud)
编辑:我甚至试过这个并没有帮助:
unsafe
{
String utfeightstring = null;
string sourcetext = "value with special character ©";
Console.WriteLine(sourcetext);
// Convert a string to …
Run Code Online (Sandbox Code Playgroud) c# ×5
.net ×2
sql-server ×2
datagridview ×1
datasource ×1
generics ×1
pivot ×1
postgresql ×1
sql ×1
uri ×1
utf-8 ×1
wcf ×1
webserver ×1