DiscoveryClient.GetAsync cannot connect to server - identityserver4

I have an issue when I am trying to set up this code:
var discoClient = new DiscoveryClient("http://localhost:5000") {Policy =
{RequireHttps = false}};
var disco = await discoClient.GetAsync();
The second line, var disco, tells me that it had issues connecting to the server, and I am at a loss trying to figure out why.
I am going through this tutorial: https://identityserver4.readthedocs.io/en/release/quickstarts/1_client_credentials.html.
I have everything else up to that point setup just like the walkthrough
What do I need to do to make this work?

Make sure you have both projects running.
In Solution Explorer select the solution file at the top.
Then right click and select the properties menu option.
Select the 'Multiple startup projects' and make sure the IdentityServer and Client Projects are set to 'Start'.

Related

CPQ Quote API, I can't save the quote

I can't save the quote.
Doing the query:
select
ApexClass.name, Id, CreatedDate, CreatedById, JobType,
ApexClassId, Status, JobItemsProcessed, TotalJobItems,
NumberOfErrors, CompletedDate, MethodName, ExtendedStatus,
ParentJobId, LastProcessed, LastProcessedOffset
from
AsyncApexJob
order by
CreatedDate desc
I get this error:
Calculation error on quote Q-13761: "UNAUTHORIZED"
Code:
public with sharing class QuoteCalculator {
public void calculate(QuoteModel quote, String callbackClass) {
system.debug('quote: ' +quote);
system.debug('callbackClass: ' +callbackClass);
QuoteCalculatorContext ctx = new QuoteCalculatorContext(quote, callbackClass);
SBQQ.ServiceRouter.load('SBQQ.QuoteAPI.QuoteCalculator', null, JSON.serialize(ctx));
system.debug('QuoteCalculator.calculate');
}
private class QuoteCalculatorContext {
private QuoteModel quote; //The quote and callbackClass properties are called
in the API code by the exact names seen here.
private String callbackClass; //Altering these property names will cause
calculator API calls to fail.
private QuoteCalculatorContext(QuoteModel quote, String callbackClass) {
this.quote = quote;
this.callbackClass = callbackClass;
}
}
}
anonymous window:
QuoteReader reader = new QuoteReader();
QuoteModel quote = reader.read('a0p1w000BhfXzAAJ');
System.debug(quote);
quote.lineItems[0].record.SBQQ__Quantity__c = 2;
QuoteCalculator calculator = new QuoteCalculator();
calculator.calculate(quote, 'MyCallback')
Preface
I had (almost) the same exact code base as yours, and got the same error message.
In my case there was an other sandbox I could test my code, and it turned out to be working properly there.
Cause
Later found out that the Salesforce CPQ's Calculation Quote API is using Heroku to do the calculations in order to avoid apex limits exhaustion.
From this it can be deducted, that it needs to have a Connected App. I checked the Apps -> Connected Apps setup, and found that no record was listed under the "Connected Apps OAuth Usage" page for the Salesforce CPQ. (On my other sandbox there was a "Steelbrick CPQ" row.)
From this I concluded that this might be the reason for this behaviour.
Seems like something went wrong during the "Authorize new Calculation Service" process. (Or there was a sandbox refresh and something else went wrong during it.)
Solution
The bad news is that the option to authorize a new calculation service is only visible for the first time you configure the package, which you might already done. (Well... if you haven't done, then this is a great news, because your problem is probably solved. :D) (Otherwise read further.)
The good news is I figured out a solution for the case when you already done this, yet that "Steelbrick CPQ" row is missing.
Created a scratch org and installed the Salesforce CPQ package, then before I clicked on the "Authorize new Calculation Service" link under the "Pricing and Calculation" tab in the Settings Editor, I checked the source code in hope of finding something of interest.
I did.
This link: https://rest-na.steelbrick.com/oauth/auth/https%3A%2F%2Ftest.salesforce.com/SBQQ
(⚠️NOTE: You might have to change it according to your location. There are several servers across the globe:
rest-au.steelbrick.com
rest-eu.steelbrick.com
rest-jp.steelbrick.com
rest-na.steelbrick.com
But for me the above pasted link was generated on the settings page. Which is only interesting, because I live in the EU, yet, for some reason I got the link to the rest-NA server... whatever.gif
So just make sure if you click on the link, in the address bar you can find the appropriate salesforce instance URL.)
Conclusion
With this link you won't have to reinstall the package, you just have to click on it, and allow the access from Steelbrick and the missing row will appear, and you will be authorized to use the Calculation API.

How can I troubleshoot Launch Darkly SDK when it fails to get flag values?

I'm trying to set up a simple Launch Darkly integration in .NET but it isn't working. The code seems to run just fine, but it doesn't actually get the flag value. It always returns false regardless of whether I turn the flag on or off in my Launch Darkly dashboard.
Here's my code:
LdClient client = new LdClient("my sdk key");
var user = LaunchDarkly.Sdk.User.WithKey("12345");
var anonymous = LaunchDarkly.Sdk.User.Builder(Session.SessionID).Anonymous(true).Build();
bool enabledForUser = client.BoolVariation("website-poc", user);
bool enabledForAnonymous = client.BoolVariation("website-poc", anonymous);
client.Dispose();
The variables "enabledForUser" and "enabledForAnonymous" always return false. How can I troubleshoot the issue? What are some possible reasons why it's not working? (Note: the client object's "Initialized" property shows up as true, so I assume that means the connection was successful.)
Here's what my flag looks like on the Launch Darkly dashboard. The green "On" toggle means that it should be returning true, right?
I figured out the issue. I was using the SDK key for the wrong project. You can use the yellow drop-down on the dashboard to see which project you're working with.

node.js doesn't seem to recognize sql.connection in some certain situation

I am very new to node.js and am now trying to build a connection using node.js to a MSSQL database. When the codes are being simpler say something like this:
var sql = require("mssql");
const pool = sql.connect('mssql://username:password#localhost/database')
The console doesn't give me any warning or errors on running the line for connection. I thought that means I'm good so I tried some other things but it says TypeError: sql.Conection is not a constructor when I was trying on this:
var dbConfig = {
server: "localhost\\server",
database: "database",
user: "user",
password: "password",
port: 1433
};
function getEmp() {
var conn = new sql.Connection(dbConfig);
//Some other codes...
}
And if I try to remove the new over there it says TypeError: sql.Conection is not a function on the console.
This makes me feel like it suddenly not recognizing the sql but I was not getting such an error with the simple version of the code.
So my question is what was wrong with the code and if it did work in the first code and how to make the second code work.
Thanks in advance.
Seems like you should be doing var conn = sql.connect(dbConfig). See the module's documentation for more information.
I found the problem. It is the problem on the syntax on sql.Connection(dbConfig). With the help of someone else, he found that the contractor of the sql module has changed to ConnectionPool.
So, after changing the syntax to the correct one, things went smooth (except I got into trouble for having some stupid name for a SQL table, but that's solved and also not quite related to this question) and problem solved.
Thank you for your time.

Send data to .php with Cocoonjs Canvas+

I have a game finished and I´m saving the scores in a database perfectly, only if I use webview+, if I change to canvas+ the save proccess is not working (and no errors).
I´m trying to save this data sending it to a php file connected to de database (as I said, is working using webview or webview+)
How would you do this using canvas+?
var http = new XMLHttpRequest();
var url = path+"getScores.php";
var params = "game=1&order=ASC";
http.open("POST", url, true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);
Please, try passing the parameters in the request URL using a GET (just in case). Also, try compiling a custom launcher in the cloud using the latest version (2.1.1). Actually, the JQuery errors should disappear by doing this.
And as Iker said, you can fix this with a custom launcher. I didn´t know about this thing but well, it´s working perfectly now, so if you have this problem, just try that and good luck.

WCF Data Service and Silverlight: DataServiceQuery<T> will not re-perform query

Using Silverlight 4, Oracle 11g, and Entity Framework 4.
I use a DataServiceQuery to fill a DataGrid. Then, some local (non-EF) code updates the DB. I would like to use the same query to refresh the DataGrid with the updated/new data. The problem is, when I do that, it returns the old, original results. I have verified that the changes have, in fact, been committed to the DB prior to this code running:
DataServiceContext<T> dsContext= new DataServiceContext<T>(uri);
dsContext.MergeOption = MergeOption.NoTracking;
dsContext.SaveChangesDefaultOptions = SaveChangesOptions.ReplaceOnUpdate;
DataServiceQuery<T> dsQuery = dsContext.CreateQuery<T>(typeof(T).Name);
// oldQuery is an IQueryable<T>
dsQuery = (DataServiceQuery<T>)oldQuery;
var dsQuery = (DataServiceQuery<T>)oldQuery;
dsQuery.BeginExecute(new AsyncCallback(c =>
{
IEnumerable<T> result = dsQuery.EndExecute(c);
listSelectedRecord = new List<T>();
listSelectedRecord = result.ToList();
}), dsQuery);
As far as I can tell, the new dsQuery is not even being sent to the Oracle server, even though a new DataServiceContext is being created. It is apparently discovering that it has a cached copy somewhere. If I type the query into a browser, it returns the updated results.
Any suggestions on how to force the DS to reperform the query?
Assigning oldQuery to the newly instantiated dsQuery object apparently copies cached results from somewhere. The solution I used here was to replace
dsQuery = (DataServiceQuery<T>)oldQuery;
with
dsQuery = (DataServiceQuery<T>)(dsQuery.Provider.CreateQuery<T>(oldQuery.Expression));
I would still like to understand exactly where, why, and how these results are being cached. The DataServiceQuery<T> docs don't say anything about this:
http://msdn.microsoft.com/en-us/library/cc646574(v=vs.95).aspx
You can try deleting your .suo file if you see this behavior when debugging.
The astonishing answers to this question seem to be found here:
Does Silverlight cache web service calls?
and
https://connect.microsoft.com/VisualStudio/feedback/details/340931/silverlight-webclient-does-not-download-updated-resources
There seems to be be some sort of vague consensus that SLx does indeed rely on the browser cache, not that you would know that from the DataService, DataServiceContext, or DataServiceQuery docs.
So the easiest fix for this, in IE 8 at least, is to turn off browser caching.

Resources