本文整理汇总了C#中JsonServiceClient.GetAsync方法的典型用法代码示例。如果您正苦于以下问题:C# JsonServiceClient.GetAsync方法的具体用法?C# JsonServiceClient.GetAsync怎么用?C# JsonServiceClient.GetAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonServiceClient
的用法示例。
在下文中一共展示了JsonServiceClient.GetAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnCreate
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
//AndroidPclExportClient.Configure();
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
var btnSync = FindViewById<Button>(Resource.Id.btnSync);
var btnAsync = FindViewById<Button>(Resource.Id.btnAsync);
var btnAwait = FindViewById<Button>(Resource.Id.btnAwait);
var txtName = FindViewById<EditText>(Resource.Id.txtName);
var lblResults = FindViewById<TextView>(Resource.Id.lblResults);
//10.0.2.2 = loopback
//http://developer.android.com/tools/devices/emulator.html
var client = new JsonServiceClient("http://10.0.2.2:81/");
btnSync.Click += delegate
{
try
{
var response = client.Get(new Hello { Name = txtName.Text });
lblResults.Text = response.Result;
}
catch (Exception ex)
{
lblResults.Text = ex.ToString();
}
};
btnAsync.Click += delegate
{
client.GetAsync(new Hello { Name = txtName.Text })
.Success(response => lblResults.Text = response.Result)
.Error(ex => lblResults.Text = ex.ToString());
};
btnAwait.Click += async delegate
{
try
{
var response = await client.GetAsync(new Hello { Name = txtName.Text });
lblResults.Text = response.Result;
}
catch (Exception ex)
{
lblResults.Text = ex.ToString();
}
};
}
示例2: IsAlive
public async Task IsAlive()
{
var client = new JsonServiceClient(AcDomain.NodeHost.Nodes.ThisNode.Node.AnycmdApiAddress);
var isAlive = new IsAlive
{
Version = "v1"
};
var response = await client.GetAsync(isAlive);
Assert.IsTrue(response.IsAlive);
isAlive.Version = "version2";
response = await client.GetAsync(isAlive);
Assert.IsFalse(response.IsAlive);
Assert.IsTrue(Status.InvalidApiVersion.ToName() == response.ReasonPhrase, response.Description);
}
示例3: Can_report_progress_when_downloading_async
public async Task Can_report_progress_when_downloading_async()
{
var hold = AsyncServiceClient.BufferSize;
AsyncServiceClient.BufferSize = 100;
try
{
var asyncClient = new JsonServiceClient(ListeningOn);
var progress = new List<string>();
//Note: total = -1 when 'Transfer-Encoding: chunked'
//Available in ASP.NET or in HttpListener when downloading responses with known lengths:
//E.g: Strings, Files, etc.
asyncClient.OnDownloadProgress = (done, total) =>
progress.Add("{0}/{1} bytes downloaded".Fmt(done, total));
var response = await asyncClient.GetAsync(new TestProgress());
progress.Each(x => x.Print());
Assert.That(response.Length, Is.GreaterThan(0));
Assert.That(progress.Count, Is.GreaterThan(0));
Assert.That(progress.First(), Is.EqualTo("100/1160 bytes downloaded"));
Assert.That(progress.Last(), Is.EqualTo("1160/1160 bytes downloaded"));
}
finally
{
AsyncServiceClient.BufferSize = hold;
}
}
示例4: TransmitCoreAsync
protected async override Task<IMessageDto> TransmitCoreAsync(DistributeContext context)
{
try
{
var client = new JsonServiceClient(context.Responder.AnycmdApiAddress);
return await client.GetAsync(GetRequest(context));
}
catch (Exception ex)
{
context.Exception = ex;
return null;
}
}
示例5: IsAliveCoreAsync
protected async override Task<IBeatResponse> IsAliveCoreAsync(BeatContext context)
{
try
{
var client = new JsonServiceClient(context.Node.Node.AnycmdApiAddress);
return await client.GetAsync(GetRequest(context));
}
catch (Exception ex)
{
context.Exception = ex;
return null;
}
}
示例6: OnCreate
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
AndroidPclExportClient.Configure();
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
var button = FindViewById<Button>(Resource.Id.MyButton);
button.Click += delegate { button.Text = string.Format("{0} clicks!!", count++); };
var btnGoSync = FindViewById<Button>(Resource.Id.btnGoSync);
var btnGoAsync = FindViewById<Button>(Resource.Id.btnGoAsync);
var txtName = FindViewById<EditText>(Resource.Id.txtName);
var txvResults = FindViewById<TextView>(Resource.Id.txvResults);
//10.0.2.2 = loopback
//http://developer.android.com/tools/devices/emulator.html
var client = new JsonServiceClient("http://10.0.2.2:81/");
btnGoSync.Click += delegate
{
try
{
var response = client.Get(new Hello { Name = txtName.Text });
txvResults.Text = response.Result;
}
catch (Exception ex)
{
txvResults.Text = ex.ToString();
}
};
btnGoAsync.Click += delegate
{
client.GetAsync(new Hello { Name = txtName.Text })
.Success(response => {
txvResults.Text = response.Result;
})
.Error(ex => {
txvResults.Text = ex.ToString();
});
};
}
示例7: TemplateForm_Load
private async void TemplateForm_Load(object sender, EventArgs e)
{
if (ontologies == null)
{
try
{
ShowProgressBar();
lblCaption.Text = "努力加载中……";
var getAllOntology = new GetAllOntologies();
var client = new JsonServiceClient(serviceBaseUrl);
var response = await client.GetAsync(getAllOntology);
ontologies = response.Ontologies;
foreach (var ontology in ontologies)
{
if (!ontology.IsSystem)
{
var pnl = new FlowLayoutPanel()
{
Tag = ontology,
AutoScroll = true
};
var tabPage = new TabPage() { Text = ontology.Name, Tag = pnl };
tabPage.Controls.Add(pnl);
pnl.Dock = DockStyle.Fill;
tabControl.TabPages.Add(tabPage);
foreach (var element in ontology.Elements)
{
var chkb = new CheckBox()
{
Text = element.Name + "(" + element.Key + ")",
Tag = element,
Width = 150
};
chkb.CheckedChanged += chkb_CheckedChanged;
pnl.Controls.Add(chkb);
}
}
}
HideProgressBar();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
示例8: btnAuth_Click
private async void btnAuth_Click(object sender, RoutedEventArgs e)
{
try
{
var client = new JsonServiceClient("http://localhost:81/");
await client.PostAsync(new Authenticate
{
provider = "credentials",
UserName = "user",
Password = "pass",
});
var response = await client.GetAsync(new HelloAuth { Name = "secure" });
lblResults.Content = response.Result;
}
catch (Exception ex)
{
lblResults.Content = ex.ToString();
}
}
示例9: GetResponse
private static Task<WeatherResponse> GetResponse(string m_uri)
{
JsonServiceClient client = new JsonServiceClient("http://api.wunderground.com/api");
return client.GetAsync<WeatherResponse>(m_uri);
}
示例10: Load_test_GetFactorialGenericAsync_async
public async Task Load_test_GetFactorialGenericAsync_async()
{
var client = new JsonServiceClient(Config.ServiceStackBaseUri);
int i = 0;
var fetchTasks = NoOfTimes.Times(() =>
client.GetAsync(new GetFactorialGenericAsync { ForNumber = 3 })
.ContinueWith(t =>
{
if (++i % 100 == 0)
{
"{0}: {1}".Print(i, t.Result.Result);
}
}));
await Task.WhenAll(fetchTasks);
}
示例11: Action_Get_PerformanceAsync
public async Task Action_Get_PerformanceAsync()
{
var client = new JsonServiceClient(AcDomain.NodeHost.Nodes.ThisNode.Node.AnycmdApiAddress);
for (int i = 0; i < 1000; i++)
{
var request = new Message
{
MessageId = System.Guid.NewGuid().ToString(),
Version = "v1",
Verb = "Get",
MessageType = "action",
IsDumb = false,
Ontology = "JS",
Body = new BodyData(new KeyValueBuilder().Append("Id", Guid.NewGuid().ToString()).ToArray(), null),
TimeStamp = DateTime.UtcNow.Ticks
}.JspxToken();
var response = await client.GetAsync(request);
}
}
示例12: OnCreate
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
//AndroidPclExportClient.Configure();
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
var btnGoSync = FindViewById<Button>(Resource.Id.btnGoSync);
var btnGoAsync = FindViewById<Button>(Resource.Id.btnGoAsync);
var btnGoShared = FindViewById<Button>(Resource.Id.btnGoShared);
var btnTest = FindViewById<Button>(Resource.Id.btnTest);
var txtName = FindViewById<EditText>(Resource.Id.txtName);
var lblResults = FindViewById<TextView>(Resource.Id.lblResults);
//10.0.2.2 = loopback
//http://developer.android.com/tools/devices/emulator.html
var client = new JsonServiceClient("http://10.0.2.2:81/");
var gateway = new SharedGateway("http://10.0.2.2:81/");
btnGoSync.Click += delegate
{
try
{
var response = client.Get(new Hello { Name = txtName.Text });
lblResults.Text = response.Result;
}
catch (Exception ex)
{
lblResults.Text = ex.ToString();
}
};
btnGoAsync.Click += delegate
{
client.GetAsync(new Hello { Name = txtName.Text })
.Success(response => lblResults.Text = response.Result)
.Error(ex => lblResults.Text = ex.ToString());
};
btnTest.Click += delegate
{
try
{
var dto = new Question
{
Id = Guid.NewGuid(),
Title = "Title",
};
var json = dto.ToJson();
var q = json.FromJson<Question>();
lblResults.Text = "{0}:{1}".Fmt(q.Id, q.Title);
}
catch (Exception ex)
{
lblResults.Text = ex.ToString();
}
};
btnGoShared.Click += async delegate
{
try
{
var greeting = await gateway.SayHello(txtName.Text);
lblResults.Text = greeting;
}
catch (Exception ex)
{
var lbl = ex.ToString();
lbl.Print();
lblResults.Text = ex.ToString();
}
};
}
示例13: OnCreate
protected override void OnCreate(Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
client = new JsonServiceClient ("http://10.1.1.109/api");
PopulateSelectUsers ();
Spinner usersSpinner = FindViewById<Spinner> (Resource.Id.usersSpinner);
usersSpinner.ItemSelected += (object sender, AdapterView.ItemSelectedEventArgs e) =>
{
var selectedUser = users[usersSpinner.SelectedItemPosition];
TextView goalTextView = FindViewById<TextView> (Resource.Id.GoalTotal);
TextView totalTextView = FindViewById<TextView> (Resource.Id.Total);
goalTextView.Text = selectedUser.Goal.ToString();
totalTextView.Text = selectedUser.Total.ToString();
};
// event for add user
var addUserButton = FindViewById<Button> (Resource.Id.AddUser);
addUserButton.Click += (object sender, EventArgs e) => {
TextView goalTextView = FindViewById<TextView> (Resource.Id.Goal);
TextView nameTextView = FindViewById<TextView> (Resource.Id.Name);
var goal = int.Parse (goalTextView.Text);
var response = client.Send (new AddUser { Goal = goal, Name = nameTextView.Text });
PopulateSelectUsers ();
goalTextView.Text = string.Empty;
nameTextView.Text = string.Empty;
Toast.MakeText (this, "Added new user", ToastLength.Short).Show();
};
// event for add Protein
var addProteinButton = FindViewById<Button> (Resource.Id.AddProtein);
addProteinButton.Click += (object sender, EventArgs e) => {
TextView amountTextView = FindViewById<TextView> (Resource.Id.Amount);
var amount = int.Parse(amountTextView.Text);
var selectedUser = users[usersSpinner.SelectedItemPosition];
var response = client.Send (new AddProtein { Amount = amount, UserID = selectedUser.Id });
selectedUser.Total = response.NewTotal;
TextView totalTextView = FindViewById<TextView> (Resource.Id.Total);
totalTextView.Text = selectedUser.Total.ToString();
amountTextView.Text = string.Empty;
//string usermessage = "Added Protein to :" & selectedUser.Name;
Toast.MakeText (this, "Added Protein to :" + selectedUser.Name, ToastLength.Short).Show();
};
client.GetAsync<UserResponse>("users",(w2) => {
Console.WriteLine(w2);
foreach(var c in w2.Users) {
Console.WriteLine(c);
Console.WriteLine(c.Name);
}
},
(w2, ex) => {
Console.WriteLine(ex.Message);
});
}
示例14: OnCreate
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your application here
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.login);
SupportToolbar mToolbar = FindViewById<SupportToolbar>(Resource.Id.loginToolbar);
SetSupportActionBar(mToolbar);
SupportActionBar.SetHomeButtonEnabled(true);
SupportActionBar.SetDisplayShowTitleEnabled(true);
progressBar = FindViewById<ProgressBar>(Resource.Id.progressBar);
animation = ObjectAnimator.OfInt(progressBar, "progress", 0, 500); // see this max value coming back here, we animale towards that value
animation.RepeatMode = ValueAnimatorRepeatMode.Reverse;
animation.RepeatCount = 100;
animation.SetDuration(1500);
animation.SetInterpolator(new FastOutLinearInInterpolator());
var btnTwitter = FindViewById<ImageButton>(Resource.Id.btnTwitter);
var btnAnon = FindViewById<ImageButton>(Resource.Id.btnAnon);
var client = new JsonServiceClient(MainActivity.BaseUrl);
btnTwitter.Click += (sender, args) =>
{
StartProgressBar();
Account existingAccount;
// If cookies saved from twitter login, automatically continue to chat activity.
if (TryResolveAccount(out existingAccount))
{
try
{
client.CookieContainer = existingAccount.Cookies;
var task = client.GetAsync(new GetUserDetails());
task.ConfigureAwait(false);
task.ContinueWith(res =>
{
if (res.Exception != null)
{
// Failed with current cookie
client.ClearCookies();
PerformServiceStackAuth(client);
StopProgressBar();
}
else
{
StartAuthChatActivity(client, existingAccount);
StopProgressBar();
}
});
}
catch (Exception)
{
// Failed with current cookie
client.ClearCookies();
StopProgressBar();
PerformServiceStackAuth(client);
}
}
else
{
StopProgressBar();
PerformServiceStackAuth(client);
}
};
btnAnon.Click += (sender, args) =>
{
StartProgressBar();
StartGuestChatActivity(client);
StopProgressBar();
};
}
示例15: OnCreate
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
//AndroidPclExportClient.Configure();
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
var btnSync = FindViewById<Button>(Resource.Id.btnSync);
var btnAsync = FindViewById<Button>(Resource.Id.btnAsync);
var btnAwait = FindViewById<Button>(Resource.Id.btnAwait);
var btnAuth = FindViewById<Button>(Resource.Id.btnAuth);
var btnShared = FindViewById<Button>(Resource.Id.btnShared);
var txtName = FindViewById<EditText>(Resource.Id.txtName);
var lblResults = FindViewById<TextView>(Resource.Id.lblResults);
//10.0.2.2 = loopback
//http://developer.android.com/tools/devices/emulator.html
var client = new JsonServiceClient("http://10.0.2.2:2000/");
var gateway = new SharedGateway("http://10.0.2.2:2000/");
btnSync.Click += delegate
{
try
{
var response = client.Get(new Hello { Name = txtName.Text });
lblResults.Text = response.Result;
using (var ms = new MemoryStream("Contents".ToUtf8Bytes()))
{
ms.Position = 0;
var fileResponse = client.PostFileWithRequest<HelloResponse>(
"/hello", ms, "filename.txt", new Hello { Name = txtName.Text });
lblResults.Text = fileResponse.Result;
}
}
catch (Exception ex)
{
lblResults.Text = ex.ToString();
}
};
btnAsync.Click += delegate
{
client.GetAsync(new Hello { Name = txtName.Text })
.Success(response => lblResults.Text = response.Result)
.Error(ex => lblResults.Text = ex.ToString());
};
btnAwait.Click += async delegate
{
try
{
var response = await client.GetAsync(new Hello { Name = txtName.Text });
lblResults.Text = response.Result;
}
catch (Exception ex)
{
lblResults.Text = ex.ToString();
}
};
btnAuth.Click += async delegate
{
try
{
await client.PostAsync(new Authenticate
{
provider = "credentials",
UserName = "user",
Password = "pass",
});
var response = await client.GetAsync(new HelloAuth { Name = "Secure " + txtName.Text });
lblResults.Text = response.Result;
}
catch (Exception ex)
{
lblResults.Text = ex.ToString();
}
};
btnShared.Click += async delegate
{
try
{
var greeting = await gateway.SayHello(txtName.Text);
lblResults.Text = greeting;
}
catch (Exception ex)
{
lblResults.Text = ex.ToString();
}
};
}