I have been trying to bring back 20 results of images using the Bing API. Here's the code:
SearchRequest request = new SearchRequest();
request.AppId = APPID;
request.Query = HttpUtility.HtmlEncode(searchQuery);
request.Sources = new SourceType[] { SourceType.Image };
request.Image = new ImageRequest();
request.Image.Count = 20;
request.Image.Filters = new string[1] { "Size:Medium" };
Now everything on here works, including the Image.Filters property. Just not the Count property. Is there a known bug or am I just missing something here?
I'm not sure really sure about this but I think you are missing setting CountSpecified property. Try this
request.Image = new ImageRequest();
request.Image.Offset = 0;
request.Image.Count = 20;
request.Image.CountSpecified = true;
request.Image.Filters = new string[1] { "Size:Medium" };
Related
I am trying to replicate the post request as given in the doc: https://learn.microsoft.com/en-us/rest/api/azure/devops/git/pushes/create?view=azure-devops-rest-5.0#update_a_file
using the .Net libraries for making an extension.
I have checked that the refUpdate and OldObjectId are correct through trial and error.
changes, item, repo are all defined and not null.
GitPush push = new GitPush();
GitCommit gitCommit = new GitCommit();
GitChange change = new GitChange();
ItemContent content = new ItemContent();
content.Content = changeString;
content.ContentType = ItemContentType.RawText;
change.NewContent = new ItemContent();
change.ChangeType = VersionControlChangeType.Edit;
change.Item = item;
List<GitChange> changes = new List<GitChange>();
changes.Add(change);
gitCommit.Changes = changes;
gitCommit.Comment = "updated app.cpp";
GitRefUpdate refUpdate = new GitRefUpdate();
refUpdate.Name = "refs/heads/dev";
refUpdate.OldObjectId = oldObjectId;
List<GitCommit> commits = new List<GitCommit>();
commits.Add(gitCommit);
List<GitRefUpdate> refUpdates = new List<GitRefUpdate>();
refUpdates.Add(refUpdate);
push.Commits = commits;
push.RefUpdates = refUpdates;
GitPush pushed = gitClient.CreatePushAsync(push, repo.Id).Result;
On the last line the debugger gives the exception that parameter "newPush" is not defined.
I have an Amazon EC2 instance and I need to be able to create an AMI (image) from it programmatically. I'm trying the following:
CreateImageRequest rq = new CreateImageRequest();
rq.InstanceId = myInstanceID;
rq.Name = instance.KeyName;
rq.Description = "stam";
rq.NoReboot = true;
IAmazonEC2 ec2;
AmazonEC2Config ec2conf = new AmazonEC2Config();
ec2 = AWSClientFactory.CreateAmazonEC2Client(ec2conf);
// CreateImageResponse imageResp;
Amazon.EC2.Model.CreateImageResponse imageResp = null;
try
{
imageResp = ec2.CreateImage(rq);
}
catch (AmazonServiceException ase)
{
MessageBox.Show(ase.Message);
}
The result is always an AmazonServiceException saying that there is a NameResolutionFailure.
How do I overcome this? I tried different possible "name" possibilities but cannot find the right one.
string amiID = ConfigurationManager.AppSettings[AmazonConstants.AwsImageId];
string keyPairName = ConfigurationManager.AppSettings[AmazonConstants.AwsKeyPair];
List<string> groups = new List<string>() { ConfigurationManager.AppSettings[AmazonConstants.AwsSecurityGroupId] };
var launchRequest = new RunInstancesRequest()
{
ImageId = amiID,
InstanceType = ConfigurationManager.AppSettings[AmazonConstants.AwsInstanceType],
MinCount = 1,
MaxCount = 1,
KeyName = keyPairName,
SecurityGroupIds = groups,
SubnetId = ConfigurationManager.AppSettings[AmazonConstants.AwsSubnetId]
};
RunInstancesResponse runInstancesResponse = amazonEc2client.RunInstances(launchRequest);
RunInstancesResult runInstancesResult = runInstancesResponse.RunInstancesResult;
Reservation reservation = runInstancesResult.Reservation;
Problem eventually solved!
it turned out thyat some codelines were doing things which were already done already and removing this part:
IAmazonEC2 ec2;
AmazonEC2Config ec2conf = new AmazonEC2Config();
ec2 = AWSClientFactory.CreateAmazonEC2Client(ec2conf);
// CreateImageResponse imageResp;
Amazon.EC2.Model.CreateImageResponse imageResp = null;
Made things clearer and no wrong repetitions happened! Now it works!
I am trying to get all the posts from google+ wall but I am able to get only 20 post. Kindly help me. My code is-
PlusService plus = new PlusService(
new Google.Apis.Services.BaseClientService.Initializer()
{
ApiKey = "AIzaSyDWG1Ho6PVC6FlPXv5rommyzCAf0ziHkTo"
});
ActivitiesResource ar = new ActivitiesResource(plus);
ActivitiesResource.ListRequest list = ar.List(id, new ActivitiesResource.ListRequest.CollectionEnum());
ActivityFeed feed = list.Execute();
Use the MaxResults property of the ListRequest class.
PlusService plus = new PlusService(
new Google.Apis.Services.BaseClientService.Initializer()
{
ApiKey = "AIzaSyDWG1Ho6PVC6FlPXv5rommyzCAf0ziHkTo"
});
ActivitiesResource ar = new ActivitiesResource(plus);
ActivitiesResource.ListRequest list = ar.List(id, new ActivitiesResource.ListRequest.CollectionEnum());
list.MaxResults = 100; // Or whatever number you want
ActivityFeed feed = list.Execute();
Note that the maximum number is 100.
Google.Apis.Orkut.v2.ActivitiesResource.ListRequest Class Reference
I am trying to get the list of UserLists on the account, but I get no entries even though during debugging the TotalNumOfEntries is 17. Screen shot is attached, any ideas why I cant see what these entries are? (sorry the details of debugger came out faint)
Code:
AdwordsUserListService usrService = (AdwordsUserListService)user.GetService(AdWordsService.v201402.AdwordsUserListService);
Selector usrSelect = new Selector();
usrSelect.fields = new String[] { "Id","Name", "Size", "MembershipLifeSpan" };
//Use predicates for filtering, if needed, later.
//Predicate usrPredicate = new Predicate();
//usrPredicate.field = "Name";
//usrPredicate.#operator = PredicateOperator.STARTS_WITH;
//usrPredicate.values = new string[] { "Poly" };
//usrSelect.predicates = new Predicate[] { usrPredicate };
usrSelect.paging = new Paging();
usrSelect.ordering = new OrderBy[] { new OrderBy() { field="Name",sortOrder=SortOrder.ASCENDING} };
UserListPage userListResult = usrService.get(usrSelect);
if (userListResult.entries != null)
{
return "Yay!";
}
Found my problem, I specified paging but didn't specify how many entries, adding this line fixed the problem.
usrSelect.paging.numberResults = 20;
I have a program that is consuming an external web service. 1 of the fields I need to send in the request is a DateTime field however it seems to never be present even though I have set it, along with many others in the same object, and they are passed fine.
I put a message inspector and had a look at what it is sending, here is the request:
<bettingRequest xmlns="">
<accountPin>0</accountPin>
<betDetailsRequestList>
<acceptPartial>0</acceptPartial>
<accumulatorBet>false</accumulatorBet>
<accumulatorId>0</accumulatorId>
<allUpFormula>0</allUpFormula>
<betAmountList>
<amountInvested>25</amountInvested>
<returnsPerBet>0</returnsPerBet>
</betAmountList>
<betRefId>0</betRefId>
<betType>Parimutuel</betType>
<scheduledType>1</scheduledType>
<fixedOddsProdCode>0</fixedOddsProdCode>
<flexiBet>false</flexiBet>
<legList>
<prodCode>1</prodCode>
<propositionNumber>0</propositionNumber>
<raceNumber>2</raceNumber>
<selectionList>
<selectionName>TIM FIN</selectionName>
<selectionNumber>6</selectionNumber>
<selectionSeparator />
</selectionList>
</legList>
<mystery>false</mystery>
<notifyMethod>0</notifyMethod>
<numMultiParlayBet>0</numMultiParlayBet>
<ordinalNumber>1</ordinalNumber>
<meetingCode>13</meetingCode>
</betDetailsRequestList>
</bettingRequest>
and here is what creates it:
bettingRequest betReq = new bettingRequest();
betDetailsReq betDetReq = new betDetailsReq();
List<legDetailsReq> leglist = new List<legDetailsReq>();
List<betSelection> sellist = new List<betSelection>();
List<betAmount> betamtlist = new List<betAmount>();
List<betDetailsReq> betdetaillist = new List<betDetailsReq>();
betSelection sel = new betSelection();
sel.selectionNumber = selection.ToString();
sel.selectionName = Runner;
sel.selectionSeparator = "";
sellist.Add(sel);
legDetailsReq leg = new legDetailsReq();
leg.prodCode = 1;
leg.propositionNumber = 0;
leg.raceNumber = racenum;
leg.selectionList = sellist.ToArray();
leglist.Add(leg);
betAmount betAmt = new betAmount();
betAmt.amountInvested = betamt;
betAmt.returnsPerBet = "0";
betamtlist.Add(betAmt);
betDetReq.betType = "Parimutuel";
betDetReq.betAmountList = betamtlist.ToArray();
betDetReq.legList = leglist.ToArray();
betDetReq.allUpFormula = "0";
betDetReq.acceptPartial = 0;
betDetReq.accumulatorBet = false;
betDetReq.betRefId = 0;
betDetReq.scheduledType = 1;
betDetReq.fixedOddsProdCode = 0;
betDetReq.flexiBet = false;
betDetReq.mystery = false;
betDetReq.notifyMethod = 0;
betDetReq.ordinalNumber = 1;
betDetReq.meetingCode = meetingcode;
betDetReq.meetingDate = DateTime.Now;
betdetaillist.Add(betDetReq);
betReq.betDetailsRequestList = betdetaillist.ToArray();
bettingResponse resp = bet.validateBet(meta, betReq);
and here is the code for the serialization:
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=11)]
public System.DateTime meetingDate {
get {
return this.meetingDateField;
}
set {
this.meetingDateField = value;
this.RaisePropertyChanged("meetingDate");
}
}
The attribute that is missing is the betDetReq.meetingDate, the WSDL can be viewed at https://api.tab.com.au/tabapi/services/betting?wsdl
Can someone tell me where I am going wrong please? I have tried many different variations of DataTime all with the same missing result.
Thanks
Dean
Ensure you have set the "Specified" property to true.
betDetReq.meetingDate = DateTime.Now;
betDetReq.meetingDateSpecified = true;
If you have an optional field (i.e. one where the minOccurs attribute is 0), then the proxy includes a "Specified" property. Unless you set this to true, the field does not get added to the request body.