Where & how does one instantiate ServiceInitializationParameters in an Azure Service Fabric service? - c#

Trying to use custom application configuration in my service. This post gives part of the answer, but it doesn't explain how & where you initialize the ServiceInitializationParameters object, which is required to get it working. The object does not seem to have a constructor. Documentation from Microsoft is sketchy and the provided sample on GitHub does not seem to use any custom app config.

This post is based on the preview SDK. In the release version (2.0+) of the SDK, ServiceInitializationParameters was replaced with ServiceContext and its derived stateless and stateful versions. Check out the release notes for a comprehensive list of all the changes from preview to release.
Everything else in this post is still accurate, but you access the config stuff like this now:
var configurationPackage = this.Context.CodePackageActivationContext.GetConfigurationPackageObject("Config");
var connectionStringParameter = configurationPackage.Settings.Sections["UserDatabase"].Parameters["UserDatabaseConnectionString"];

Related

Azure Search set disableOrderByHighWaterMarkColumn with .NET C# API

I have a service that manages all of the indexes/indxers I use for Azure Cognitive Search, and within that I am attempting to set disableOrderByHighWaterMarkColumn to true when creating/updating an indexer.
While I do see examples in the official docs for an HTTP request to set that field, I'm not seeing any parameter anywhere (including the Parameters option under the SearchIndexer object) that can be set to update that value.
Does nadisableOrderByHighWaterMarkColumn` through the C# API? I have the latest Azure.Search.Documents package installed.
You would need to add it as a custom key under the SearchIndexer.Parameters.IndexingParametersConfiguration property.
If for some reason that doesn't work as expected, then it is a bug with the .NET SDK that I would suggest you submit as an issue against the official Github repository.

IBM Watson Unity SDK, IamAuthenticator objects cannot authenticate successfully

I am trying to query Watson Discovery News and get some responses in Unity.
First I tried to authenticate my Watson Discovery service through Discovery service APIKey(As described in the "IAM" section in https://github.com/watson-developer-cloud/unity-sdk). My code is exactly the same as the example code in "Query a collection" section in https://cloud.ibm.com/apidocs/discovery/discovery?code=unity#query-a-collection.
Unfortunately, the code always returns due to unsuccessful authentication, thus I cannot get any response. After some debugging, I found out that "tokenData" field in IamAuthenticator.cs(This is part of IBM Unity SDK) is not initialized; this leads to the unsuccessful authentication.
I was able to debug by changing the "yield return" in example code to "return". Otherwise, C# debugger cannot step into the code.
Since I have followed all the steps in IBM documentations, I am not sure how to proceed.
To reproduce the problem, one has to download IBM Unity SDK on https://github.com/watson-developer-cloud/unity-sdk and follow the instructions in README. After setting up, one could replicate the problem using the code below:
var authenticator = new IamAuthenticator(
apikey: "{apikey}"
);
while (!authenticator.CanAuthenticate())
yield return null;
Thanks in advance for any help!
Have you set the URL (SetServiceUrl) to match the location for your service instance? See Service Endpoint in the API reference
I bypassed this problem using Token authentication instead of using APIkey.
If one has the choice of using other SDKs, e.g. Java SDK, please do so. Because Watson Unity SDK is not well supported at the moment.

SCIM and web api 2

I am trying to implement SCIM with Web Api 2 (c#) and I've found the nuget package and some documentation from Microsoft and their sample code.
My understanding from the SCIM documentation is that they just need an API with the specified user/Group methods and schemas, but in the sample code they have used a monitor and provider.
public Startup()
{
IMonitor monitor = new DefaultMonitor();
IProvider provider = new SampleProvider();
this.starter = new WebApplicationStarter(provider, monitor);
}
Their code doesn't compile even after following the instructions and getting nuget packages most probably because of the old resources on the packages that they have used, but also I don't see what is the nececity of using the package other than adding some interfaces for my controllers.
I've also found this:
SCIM (System for Cross-domain Identity Management) library for C#
But it is also a shame that the blog post that they are pointing to from MS is gone :.
So what I am asking is:
- Am I going the correct direction? Should I use the nuget?
And if yes, anything special on Web api?
Any suggestion is also very appreciated.

How to call Microsoft Graph Beta API from C#

I tried to get the content of the user's profile picture and I found out that I had to call the Beta version because the current version gives the following error message:
"code": "GetUserPhoto",
"message": "The operation is not supported."
So, I tried to switch to Beta, and here is the code that I wrote in C# to do it, but it doesn't work:
Microsoft.Graph 1.6.2
List<QueryOption> options = new List<QueryOption>
{
new QueryOption("$api-version", "beta")
};
var pictureStream = await graphClient.Me.Photo.Content.Request(options).GetAsync();
I got the same error message.
I tried the same request in the Graph Explorer. The 1.0 doesn't work, but Beta works.
The api-version query parameter is used by the Azure AD Graph API. This is a different API than Microsoft Graph. There is a lot of functional overlap (Azure AD Graph is slowly being migrated over to Microsoft Graph) but they use entirely different entities and calling conventions.
In order to call the /beta endpoint using the Microsoft Graph .NET Client Library, you need to change the BaseUrl of the client:
graphClient.BaseUrl = "https://graph.microsoft.com/beta";
var pictureStream = await graphClient.Me.Photo.Content.Request().GetAsync();
Some important notes about the /beta endpoint:
It isn't supported and isn't suitable for production. So don't do that. Or at least don't tell anyone and don't call Support if it stops working. ;-)
The .NET Client uses objects constructed off the production metadata. This means that any entities, actions or properties that were added in /beta don't exist in the models shipped with the SDK.
The .NET Client will ignore any values returned by Microsoft Graph that it doesn't expect to see. So if an endpoint returns a property that wasn't included in the production metadata (see #2), it will simply be ignored.
So long as you're only using a /beta to gain functionality but still expecting /v1.0 results, it should work okay. Photos for example only look at Exchange in v1.0 but look in both Exchange and Active Directory but still return the same result. In theory this means you should be able to swap /beta for /v1.0 without a problem.
I think you are still calling V1 endpoint. In fact, the Beta endpoint is not currently supported in the Microsoft Graph .NET Client Library. More info here.
There is an official beta client for Graph API now:
https://github.com/microsoftgraph/msgraph-beta-sdk-dotnet

Is there an up-to-date c# sample for the Amazon product API?

I'm trying to create a small application that interacts with the Product API of Amazon (get prices of articles, and so on)
Unfortunately all the C# samples for the interaction with the Amazon WCF service I've found so far are outdated.
I know that Amazon decided that each service call must be signed with a personal accessKeyId and secretKey, so all minimal code samples that are older than 2009 (I think they made the change in 2009) are useless. The official Amazon documentation is useless to me as well, as it does not provide necessary information.
I've also googled two tutorial on how to access the API, and following these only result in no search results for any search tearm or simply null.
Is there an up-to-date, working, minimal sample somewhere available?
So, I finally found the solution, based on a comment posted here: http://www.falconwebtech.com/post/2010/06/14/Using-WCF-and-SOAP-to-Send-Amazon-Product-Advertising-API-Signed-Requests.aspx
This is also the URL, where I downloaded the code I made working.
I didn't pass my "Your unique Associates ID", which I didn't even had until just now. You can get it here: https://affiliate-program.amazon.com/
Add
itemSearch.AssociateTag = "YourAssociateID";
before amazonClient.ItemSearch(itemSearch).
Works like a charm
I have found a up-to-date project, the code is available on github
Nager.AmazonProductAdvertising
nuget
PM> install-package Nager.AmazonProductAdvertising
Example
var authentication = new AmazonAuthentication("accesskey", "secretkey");
var client = new AmazonProductAdvertisingClient(authentication, AmazonEndpoint.US, "YourAssociateID");
var result = await client.GetItemsAsync("B0037X9N5U");
if the solution above still won't work.
try this one.. (i use microsoft visual studio 2010)
download the sample code on http://www.falconwebtech.com/post/2010/06/14/Using-WCF-and-SOAP-to-Send-Amazon-Product-Advertising-API-Signed-Requests.aspx
we need to update service references, make little change at app.config, program.cs, and reference.cs.
app.config:
(1.) appSettings tag;
assign accessKeyId and secretKey value,
add
<add key="associateTag" value="yourAssociateTag" />.
(2.) behaviours tag -> endpointBehaviors tag -> behaviour tag -> signingBehavior tag;
assign accessKeyId and secretKey value.
(3.) bindings tag -> basicHttpBinding tag; (optional)
delete binding tag except AWSECommerceServiceBindingNoTransport
and AWSECommerceServiceBindingTransport.
(4.) client tag;
delete endpoint tag except AWSECommerceServiceBindingTransport.
program.cs:
add itemSearch.AssociateTag = ConfigurationManager.AppSettings["associateTag"]; before ItemSearchResponse response = amazonClient.ItemSearch(itemSearch);
reference.cs: (open file in service references folder using visual studio)
change private ImageSet[][] imageSetsField; to private ImageSet[] imageSetsField;
change public ImageSet[][] ImageSets {...} to public ImageSet[] ImageSets {...}
finally we can run our program and it will work. good luck..
nb: there will be 1 warning (invalid child element signing behaviour), i think we can ignore it, or if you have any solution please share.. ^^v..

Categories

Resources