我可以调用web服务但名称属性不绑定.
提琴手请求
POST http://localhost:50399/api/custservice/ HTTP/1.1
User-Agent: Fiddler
Host: localhost: 50399
Content-Length: 28
{ "request": { "name":"test"}}
Run Code Online (Sandbox Code Playgroud)
POST Webmethod
public string Any(CustomerRequest request)
{
//return details
}
Run Code Online (Sandbox Code Playgroud)
CustomerRequest.cs
public class CustomerRequest
{
public string name {get;set;}
}
Run Code Online (Sandbox Code Playgroud) 目前,我正在使用OrmLite进行数据库操作.我也打算使用Dapper ORM,但任何人都可以指出我如何在ServiceStack中集成DapperORM.我是否需要将Dapper和插件的IDbConnection和IDbConnectionFactory接口实现到容器中.
public override void Configure(Container container) {
container.Register<IDbConnectionFactory>(
c => new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["default"].ConnectionString,
SqlServerDialect.Provider));
container.Register<IDbConnection>(c => c.Resolve<IDbConnectionFactory>().OpenDbConnection()).ReusedWithin(ReuseScope.Request);
}
Run Code Online (Sandbox Code Playgroud) 我们需要在 WebAPI 项目中禁用 CORS,我已经在Startup.cs
类和public void Configuration(IAppBuilder app)
方法中注释掉了下面的行。
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
Run Code Online (Sandbox Code Playgroud)
通过线程,发送以下请求
curl -H "Origin: http://www.google.com" --verbose \ http://localhost:23422/api/values
Run Code Online (Sandbox Code Playgroud)
回复
HTTP/1/1 200 OK
Content-Type: application/json; charset=utf-8
Server: XXXX
X-SourceFiles: XXX
X-Powered-By: ASP.NET
[
"value1",
"value2"
]
Run Code Online (Sandbox Code Playgroud)
它确实有效并返回实际结果。这是否意味着 CORS 仍然受支持?我认为它不会返回任何值,因为我是从 google.com 请求的。
但是,当我尝试以下请求时。它返回405 Method Not Allowed
curl -H "Access-Control-Request-Method: GET" -H "Origin: http://google.com" --head \ http://localhost:44312/api/values
Run Code Online (Sandbox Code Playgroud)
回复
HTTP/1/1 405 Method Not Allowed
Allow: GET,POST
Content-Type: application/json; charset=utf-8
Server: XXXX
X-SourceFiles: XXX
X-Powered-By: ASP.NET
{
"message": "The requested …
Run Code Online (Sandbox Code Playgroud) 下面是NinjectHttpApplication配置..
public class MvcApplication : NinjectHttpApplication
{
public MvcApplication()
{
Error += NinjectWebsiteApplication_Error;
}
}
protected override IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Load<ApplicationConfig>();
return kernel;
}
void NinjectWebsiteApplication_Error(object sender, System.EventArgs e)
{
ILogger _iLogger = **//How to get instance of Applogger here from Ninject kernel..**
}
Run Code Online (Sandbox Code Playgroud)
下面是ApplicationConfig类......
public class ApplicationConfig : NHibernateNinjectModule
{
public ApplicationConfig()
{
//other settings such as ddl script generation is present here
}
public override void Load()
{
base.Load();
Bind<ILogger>().To<AppLogger>().InSingletonScope();
}
}
Run Code Online (Sandbox Code Playgroud) 从下面,我推断的是,当应用程序配置了委托权限时,它代表已登录用户发出所有请求.
因此,在Delegated Permissions下,我们再次列出了"以登录用户身份访问目录"选项.这实际上是做什么的?
应用程序权限:您的客户端应用程序需要直接访问Web API(无用户上下文).此类权限需要管理员同意,并且也不适用于Native客户端应用程序.
委托权限:您的客户端应用程序需要以登录用户身份访问Web API,但访问权限受所选权限的限制.除非将权限配置为需要管理员同意,否则用户可以授予此类权限.
任何人都可以解释QueryById()和GetById()之间的区别,因为它们都具有相同的签名.并且有很多常见的函数以Query和Get开头,可能会有一些我认为缺少的主要区别.
对于长时间运行的操作,如果asp.net线程被释放到服务器其他请求.在哪个线程上执行长时间运行操作以及如何在完成后获取asp.net线程.
我知道无法实例化接口,但是如果我们将其分配给对象,那么谁能解释一下如何为它分配内存。例如:
ITest obj = (ITest) new TestClass1(); //TestClass1 is a class which implements ITest
obj.MethodsDefinedInInterface();
Run Code Online (Sandbox Code Playgroud)
ITest是否转换为对象以保存TestClass1的属性和方法。
我试图了解 ASP.NET 应用程序中存储库类的范围。我假设它们在请求范围内是线程安全的,因为每个请求都在单独的线程上运行。但是让它成为单例怎么样,这是一个有效的场景吗?
由于这些类没有状态,只有操作数据的方法,因此执行这些方法的不同线程可能具有不同的堆栈帧。我的理解对吗,谁能提供更多见解。
interface ICustomerRepository
{
List<Customers> GetAll();
Customer GetById(int id);
}
public class Customer : ICustomerRepository
{
//implement methods
}
Run Code Online (Sandbox Code Playgroud) 如果 IsEnabled 属性为 true,则需要设置 Style 属性,否则不应设置。在我目前看到的示例中,设置了样式属性但未设置样式属性本身。下面的代码不能使用触发器工作。
<TabItem.Style>
<Style TargetType="TabItem">
<Style.Triggers>
<DataTrigger Binding="{Binding IsEnabled}" Value="True">
<Setter Property="Style" Value="DotcomTabItemStyle" />
</DataTrigger>
</Style.Triggers>
</Style>
</TabItem.Style>
Run Code Online (Sandbox Code Playgroud) c# ×4
servicestack ×3
asp.net ×2
asp.net-mvc ×1
azure ×1
cors ×1
dapper ×1
fiddler ×1
ninject ×1
rest ×1
scope ×1
web-services ×1
wpf ×1