我有一个.Net Web服务(.asmx),它将一个Json字符串返回给我的客户端.但是,我的一些数据非常大,偶尔会出现此错误.
字符串的长度超过maxJsonLength属性上设置的值.
我已将maxJsonLength属性更改为2147483644,但它仍然无效.请帮忙......谢谢.
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483644"/>
</webServices>
</scripting>
</system.web.extensions>
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public void GetData(string login)
{
// throw an error on this line...
string result = new JavaScriptSerializer().Serialize(service.GetData(login));
Context.Response.Write(result);
}
Run Code Online (Sandbox Code Playgroud) 我正在重构一个应用程序,并尝试添加现有函数的异步版本,以提高ASP.NET MVC应用程序的性能时间.我知道异步函数有一个开销,但我预计,如果有足够的迭代次数,从数据库加载数据的I/O密集型性质将不仅可以弥补开销损失,而且还可以获得显着的性能提升.
该TermusRepository.LoadByTermusId函数通过从数据库中检索一堆数据表(使用ADO.NET和Oracle Managed Client)来加载数据,填充模型并返回它.TermusRepository.LoadByTermusIdAsync类似的,除了它是异步的,当有多个数据表需要检索时,加载数据表下载任务的方法略有不同.
public async Task<ActionResult> AsyncPerformanceTest()
{
var vm = new AsyncPerformanceTestViewModel();
Stopwatch watch = new Stopwatch();
watch.Start();
for (int i = 0; i < 60; i++)
{
TermusRepository.LoadByTermusId<Termus2011_2012EndYear>("1");
TermusRepository.LoadByTermusId<Termus2011_2012EndYear>("5");
TermusRepository.LoadByTermusId<Termus2011_2012EndYear>("6");
TermusRepository.LoadByTermusId<Termus2011_2012EndYear>("7");
}
watch.Stop();
vm.NonAsyncElapsedTime = watch.Elapsed;
watch.Reset();
watch.Start();
var tasks = new List<Task<Termus2011_2012EndYear>>();
for (int i = 0; i < 60; i++)
{
tasks.Add(TermusRepository.LoadByTermusIdAsync<Termus2011_2012EndYear>("1"));
tasks.Add(TermusRepository.LoadByTermusIdAsync<Termus2011_2012EndYear>("5"));
tasks.Add(TermusRepository.LoadByTermusIdAsync<Termus2011_2012EndYear>("6"));
tasks.Add(TermusRepository.LoadByTermusIdAsync<Termus2011_2012EndYear>("7"));
}
await Task.WhenAll(tasks.ToArray());
watch.Stop();
vm.AsyncElapsedTime = watch.Elapsed;
return View(vm);
}
public static async Task<T> LoadByTermusIdAsync<T>(string …Run Code Online (Sandbox Code Playgroud) 目前正在尝试 Rider(用于 .Net 的 JetBrains IDE)。我曾经在 Visual Studio Enterprise 上为 c# asp.net MVC 项目工作,我想知道是否有一种方法(在 Rider 上)可以像“添加 -> 视图 -> 使用创建/删除/更新/列表”一样“Visual Studio 上的功能?
会生成这样的 CRUD 视图的东西:
@model IEnumerable<Web.Models.Warrior>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Health)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Health)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) | …Run Code Online (Sandbox Code Playgroud) asp.net-mvc asp.net-mvc-scaffolding rider visual-studio-2017
我尝试从表中获取行数:
string commandLine = "SELECT COUNT(*) FROM client";
using (MySqlConnection connect = new MySqlConnection(connectionStringMySql))
using (MySqlCommand cmd = new MySqlCommand(commandLine, connect))
{
connect.Open();
int count = (int)cmd.ExecuteScalar();
return count;
}
Run Code Online (Sandbox Code Playgroud)
我得到了例外:
Specified cast is not valid.
Run Code Online (Sandbox Code Playgroud)
知道我怎么解决它?
假设我有一个call_log名为列的表duration.让我们进一步假装当我把桌子放在一起时,我犯了duration一个错误,就是做一个varchar列而不是一个数字.现在我无法正确排序该列.我想重命名列,所以我发出...
ALTER TABLE call_log MODIFY (duration NUMBER);
Run Code Online (Sandbox Code Playgroud)
但我明白了......
ORA-01439: column to be modified must be empty to change datatype.
Run Code Online (Sandbox Code Playgroud)
我的桌子一直在使用,有数据!而且我不想丢失数据.如何在不丢失数据的情况下修改列的数据类型?
如何使用Gmail API将邮件标记为已读?
我收到了电子邮件的帖子
Thread thread = service.users().threads().get(userId, message.getThreadId()).execute();
Run Code Online (Sandbox Code Playgroud)
但它没有像gmail API网站那样的方法markRead.
我正在使用实体框架 7 并创建了两个项目。一个项目作为 ASP.NET 5 Web API 项目,另一个项目是类库项目(包),我想在其中存储我所有的数据访问层逻辑。这样我就可以将此包用于未来的另一个报告项目,我可能提供的其他附加服务。
基本上,我在 web api 项目的控制器中有一个简单的帖子,它调用了我的数据库项目中的一个函数。当函数启动数据库时,它说数据库未定义,即使它在两个项目中都定义了。
错误
{"No database providers are configured. Configure a database provider by overriding OnConfiguring in your DbContext class or in the AddDbContext method when setting up services."}
Run Code Online (Sandbox Code Playgroud)
代码
数据库项目:InsertPerson
public int InsertPerson(tbl_Person person)
{
using (var db = new AppContext())
{
try
{
db.tbl_Person.Add(person);
db.SaveChanges();
return person.PersonID;
}
catch
{
return 0;
}
}
}
Run Code Online (Sandbox Code Playgroud)
配置文件
Web API 项目:Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<AppContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"])); …Run Code Online (Sandbox Code Playgroud) 这是我的Web API,它运行正常,我的意思是当我在浏览器上输入此URL时:
http://localhost:18207/api/values/GetMyClass
Run Code Online (Sandbox Code Playgroud)
我检索这个结果:
<MyClass>
<A>a</A>
<b>b</b>
</MyClass>
Run Code Online (Sandbox Code Playgroud)
我的代码:
public class MyClass
{
public MyClass()
{
this.A = "a";
this.b = "b";
}
public string A { get; set; }
public string b { get; set; }
}
public class ValuesController : ApiController
{
public MyClass GetMyClass()
{
return new MyClass();
}
}
Run Code Online (Sandbox Code Playgroud)
我有另一个控制台应用程序来使用我的Web API并想知道,我如何拥有MyClass的复杂或对象类型?
我的控制台上的代码如下,但它返回字符串类型
static void Main(string[] args)
{
var cts = new CancellationTokenSource();
MainAsync(args, cts.Token).Wait();
}
static async Task MainAsync(string[] args, CancellationToken token)
{
string baseAddress = …Run Code Online (Sandbox Code Playgroud) 我正在努力使用 MemoryStorage 在简单的 C# 控制台应用程序上启动 Hangfire 作业。我想用 Hangfire 尝试一些东西,但我就是不知道如何配置它。
这是我的代码:
private static void Main(string[] args)
{
GlobalConfiguration.Configuration.UseMemoryStorage();
Hangfire.BackgroundJob.Enqueue(() => Console.WriteLine("fire!"));
Hangfire.RecurringJob.AddOrUpdate(() => Console.WriteLine("minute!"), Cron.Minutely);
Console.ReadKey();
}
Run Code Online (Sandbox Code Playgroud)
我没有收到任何这些消息。
我也尝试过使用JobStorage.Current = new MemoryStorage(new MemoryStorageOptions());,但它没有改变任何东西。
Flurl具有执行OAuth和基本身份验证的方法:
await url.WithBasicAuth("username", "password").GetJsonAsync();
await url.WithOAuthBearerToken("mytoken").GetJsonAsync();
Run Code Online (Sandbox Code Playgroud)
但是如何使用当前登录的用户进行Windows身份验证?Flurl构建在其上的HttpClientHandler具有属性UseDefaultCredentials但我不知道如何在Flurl中使用它.
var httpClient = new HttpClient(new HttpClientHandler()
{
UseDefaultCredentials = true
});
Run Code Online (Sandbox Code Playgroud) c# ×7
.net ×2
oracle ×2
asp.net ×1
asp.net-mvc ×1
async-await ×1
asynchronous ×1
flurl ×1
gmail-api ×1
hangfire ×1
json ×1
mysql ×1
rider ×1
sql ×1
web-services ×1