小编Vit*_*osa的帖子

为什么要明确写"私人"?

由于字段是隐式私有的,为什么在书籍,文章等中经常使用明确的声明?

c# coding-style private

30
推荐指数
5
解决办法
3129
查看次数

使用Web API Action中的HttpClient调用外部HTTP服务

我在.Net Framework 4.5上运行的ASP.Net MVC 4 Web Api项目中使用HttpClient调用外部服务

示例代码如下(忽略返回值,因为这是测试调用外部服务的示例代码):

public class ValuesController : ApiController
{
    static string _address = "http://api.worldbank.org/countries?format=json";
    private string result;

    // GET api/values
    public IEnumerable<string> Get()
    {
        GetResponse();
        return new string[] { result, "value2" };
    }

    private async void GetResponse()
    {
        var client = new HttpClient();
        HttpResponseMessage response = await client.GetAsync(_address);
        response.EnsureSuccessStatusCode();
        result = await response.Content.ReadAsStringAsync();
    }
}
Run Code Online (Sandbox Code Playgroud)

虽然私有方法中的代码确实可以解决我的问题,但是Controller Get()调用了GetResponse(),但是它没有等待结果,而是立即执行带有result = null的返回.

我也尝试过使用WebClient进行更简单的同步调用,如下所示:

 // GET api/values
    public IEnumerable<string> Get()
    {
        //GetResponse();

        var client = new WebClient();

        result = …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-web-api dotnet-httpclient

25
推荐指数
1
解决办法
4万
查看次数

如何使用azure存储表每秒获得更多10个插入

我编写简单的WorkerRole,将测试数据添加到表中.插入代码是这样的.

var TableClient = this.StorageAccount.CreateCloudTableClient();
TableClient.CreateTableIfNotExist(TableName);
var Context = TableClient.GetDataServiceContext();

this.Context.AddObject(TableName, obj);
this.Context.SaveChanges();
Run Code Online (Sandbox Code Playgroud)

此代码针对每个客户端请求运行.我用1-30个客户端线程进行测试.我有很多不同大小的实例.我不知道我做错了什么,但我无法达到每秒10次插入.如果有人知道如何提高速度请告诉我.谢谢

UPDATE

  • 删除CreateTableIfNotExist对我的插入测试没有任何影响.
  • 切换模式为expect100Continue ="false"useNagleAlgorithm ="false"在插入速率跳至30-40 ips时产生短时间效果.但是,30秒后,插入速率降至6 ips,超时率为50%.

c# azure azure-table-storage

11
推荐指数
1
解决办法
5926
查看次数

获得"这个类不符合关键值的关键值编码." 请求RestKit loadObjectsAtResourcePath时

我正在尝试使用RestKit的RKObjectManager将JSON数据反序列化到我的iPhone应用程序中.

我目前的问题是应用程序崩溃了:

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Course 0x6e71b10> valueForUndefinedKey:]: this class is not key value coding-compliant for the key id.'
Run Code Online (Sandbox Code Playgroud)

我打电话的时候:

[manager loadObjectsAtResourcePath:@"/courses" delegate:nil];
Run Code Online (Sandbox Code Playgroud)

我的域类 - Course.h看起来像

#import <Foundation/Foundation.h>



@interface Course : NSObject  {

}

@property(nonatomic) NSInteger *id;

@property(nonatomic, retain) NSString *name;

-(id)initWithIdAndName: (NSInteger *)inId inName:(NSString *)inName;
@end
Run Code Online (Sandbox Code Playgroud)

而Course.m看起来像

#import "Course.h"
#import "NSDictionary+RKAdditions.h"


@implementation Course {

}
@synthesize name = _name;
@synthesize id = _id;

- (id)initWithIdAndName:(NSInteger *)inId inName:(NSString *)inName {
    _name = inName;
    _id …
Run Code Online (Sandbox Code Playgroud)

objective-c restkit ios5 xcode4.2

1
推荐指数
2
解决办法
9138
查看次数

C#正则表达式,字符串的开头

我想问一个关于正则表达式的简单问题:

我怎样才能比较字符串的开头?

例如:Car [200; 200; 200],自行车[20]

if (item.Name == "Car*") { textBox.Text = "Car"; }
Run Code Online (Sandbox Code Playgroud)

我不知道我必须键入什么而不是"*"来使字符串的其余部分无关紧要.

c# regex string

0
推荐指数
1
解决办法
393
查看次数