DevOps API - C# Retrieve list of Projects using Client Libraries - c#

I am trying to get THIS example to work (.Net Client Libraries example) - however everything I have attempted results in an error:
Basic authentication requires a secure connection to the server.
There is another example using the REST Api at the top of the page I linked and this works perfectly fine. For some reason, I just cant get this working using the libraries!
My code looks like this:
Uri uri = new Uri("http://adtfs:8080/tfs/{MyCompany}");
string personalAccessToken = "MyPATString";
VssBasicCredential credentials = new VssBasicCredential("", personalAccessToken);
using (ProjectHttpClient projectHttpClient = new ProjectHttpClient(uri, credentials))
{
IEnumerable<TeamProjectReference> projects = projectHttpClient.GetProjects().Result;
}
As I mentioned, using the same URL and PAT in the REST API example works fine, but for the libraries, I just cant get beyond the error mentioned above.
Am I missing something or can anyone suggest anything else I could try please?

Change http=>https from http://adtfs:8080/tfs/{MyCompany} to https://adtfs:8080/tfs/{MyCompany} ... easiest answer there was I guess works glad it helped ... but just as precautionary tale, I'll add this for posterity, you should use https anyways if the server supports it (had an app that was working sometimes slow, sometimes fast and I couldn't figure out why until I saw this https://httpvshttps.com, turns out the https tunnel was always being recreated cause I put http instead of https and the server was set to always switch to https).

Related

Integrating Adyen in .Net, getting Unauthorized response

I am trying to integrate Adyen in a .net application.
Downloaded the sample code from their Github repository and hardcoded the api-key, merchant and client keys in the code to make sure they are getting populated.
Running the code from my localhost
I am getting this error
{"status":401,"errorCode":"000","message":"HTTP Status Response - Unauthorized","errorType":"security"}
at this line:
var res = _checkout.Sessions(sessionsRequest);
Sample code is here
https://github.com/adyen-examples/adyen-dotnet-online-payments
Any idea of what I am missing?, anyone faced the same issue?
Thanks!
Thank you, i was able to get successful calls after checking how those keys are set to the environment variables. Also Client key is important.

Google Cloud API not returning any response

Background information:
I'm trying to create a PoC for Google Cloud Vision API using their .NET library.
What I have done:
Create a simple console apps with the following code for Vision API.
GoogleCredential credential = GoogleCredential.FromFile(ConfigurationManager.AppSettings["GoogleCredentialFile"]);
Grpc.Core.Channel channel = new Grpc.Core.Channel(Google.Cloud.Vision.V1.ImageAnnotatorClient.DefaultEndpoint.ToString(), credential.ToChannelCredentials());
var client = Google.Cloud.Vision.V1.ImageAnnotatorClient.Create(channel);
var image = Google.Cloud.Vision.V1.Image.FromFile(#"C:\Users\u065340\Documents\sample.jpg");
var response = client.DetectLabels(image);
foreach (var annotation in response)
{
if (annotation.Description != null)
result = annotation.Description;
}
Problem:
The line client.DetectLabels(image) gets stuck for a long time before ultimately throwing the error Deadline Exceeded.
My code sits behind a corporate proxy, but I have validated that it is not blocking internet access because I can call https://vision.googleapis.com/$discovery/rest?version=v1 from the same apps and get its JSON response just fine.
Any suggestions?
After digging around through github issues related to proxies as suggested by Jon Skeet, I found that Google Cloud Client APIs can be generally divided into 2 categories (Ref: here): REST-based HTTP 1.1 with JSON and gRPC.
For APIs associated as REST-based, there should be no issue with proxies. The problem starts to appear when we are using gRPC-based APIs such as Google Cloud Vision and Google Speech. In gRPC, we need to explicitly provide our proxy server information.
For those using Java Client, it seems we still can't set proxy properly because it will eventually be ignored, and causing the Deadline Exceeded error. This issue is already well known and can be found at here and further traced into here.
The Google team has determined that it is indeed a bug, and the status remains Open.
As for C# Client, we can set proxy information using gRPC Environment Variables which is documented in here. The code is Environment.SetEnvironmentVariable("http_proxy", <your_proxy_server>);
After I set the http_proxy environment variable pointing to my proxy server, all is well again. I get the expected output "This API needs Billing Account".
Many thanks to Jon Skeet for pointing me in the right direction :D

Incorrect Autodiscovery URL when making use of EWS Managed API

I am making use of the EWS managed API and it used to work perfectly until one fine day the autodiscover url changed (Is it possible?).
The code is pretty straight forward:
service.Credentials = new NetworkCredential("email#contoso.com", userData.Password);
service.AutodiscoverUrl("email#contoso.com", RedirectionUrlValidationCallback);
The url which I am getting is as follows: https://contoso.com/EWS.Exchange.asmx (note the EWS.Exchange).
I have enabled the tracing and that url is also in the traces but I got stuck.
Anyone has any ideas to why this is happening? I tried to search but found nothing.
Oh yes, the exchange which I am using is exchange 2007.
Thanks!
My guess is there is a misconfiguration somewhere. You might start by checking your EWS settings on the Client Access Server: Get-WebServicesVirtualDirectory -Identity EWS(default web site)
So, what I did was start from the beginning.
I removed my current certificates and created new ones... and it worked!
I do not understand why but hopefully it will help others as well :).
I followed this tutorial: http://www.howtogeek.com/107415/it-how-to-create-a-self-signed-security-ssl-certificate-and-deploy-it-to-client-machines/

Google Freebase Api C# .Net Example

I am new to developing with the Goolge API’s. I am trying to get the Google.Apis.Freebase.V1 API working in C#. Does anyone have a small example on using this API in C#? I have spent the last several days looking and can only find a couple of examples for the old Freebase Api. Nothing for the Google API.
I am just looking for a simple example on setting up a connection to the API, doing a search, then how to handle a MQL query back into a Json object. The simpler the better.
Thanks
Scott
The correct code to do a MQL query in C# using the Google API Client Library should look something like this:
string API_KEY = "your-api-key-here";
FreebaseService service = new FreebaseService{ Key = API_KEY };
String query = "[{\"id\":null,\"name\":null,\"type\":\"/astronomy/planet\"}]";
FreebaseService.MqlreadRequest request = service.Mqlread(query);
string response = request.Fetch();
Console.WriteLine (response);
Unfortunately, there seems to be some sort of error with the client library right now as its not returning any results. I'll try to figure out what's going on there.
Update: The problem appears to be that the client library passes along an alt=json parameter which the Freebase API is unable to support. The Python client library has a way to disable this but there no way to do it in .Net. You can follow the open bug for this on the Google Code project.

HttpListenerRequest is not returning a client certificate

I'm using an HttpListener to create a very basic web server. I've got it setup to use SSL using the httpcfg tool to bind to the appropriate port and certificate. This seems to be working fine. I'd now like to use client certificate authentication. So I added a call to GetClientCertificate on the HttpListenerRequest object but it is always coming back with null. My test client is very simple:
HttpWebRequest webReq = (HttpWebRequest) WebRequest.Create("https://127.0.0.1:8080/ssltest/");
webReq.ClientCertificates.Add(new X509Certificate2("ssltest.pfx", "ssltest"));
webReq.GetResponse();
I noticed that the httpcfg tool has a flag that indicates if client certificates should be negotiated so I tried specifying that flag (-f 2) but I'm still not getting the client cert. I also came across this Microsoft support issue which seems pretty relevant but I'm using the latest .NET 2.0 service pack and I've also tried the httpcfg flag both of which should avoid the issue.
I am assuming I am missing something obvious here. Any ideas?
Edit: I just found this question which seems very relevant (maybe even a duplicate?). Unfortunately there is no accepted answer for that question either. The suggested answer makes a suggestion for something I already tried (httpcfg tool with the appropriate flag).
According to http://support.microsoft.com/kb/895971/en-us the HttpWebRequest.ClientCertificates.Add performs validation already so the cert fails validation on the client-side and never gets sent.
The above link contains code to relax the validation... NEVER use that in production!!!

Categories