XSockets. version 3.06 getting Net net::ERR_CONNECTION_REFUSED with wss:// - websocket

I’m running into an issue getting wss:// to work on version 3.06 in production.
I’ve been able to get it working in a test environment locally (see test environment settings at the end).
If I used ws:// and not wss://, the production server works
In production I get the following error: net::ERR_CONNECTION_REFUSED
(Note: when I use ws://, I’ve switched over my test web site to http:// and not https://
Production environment:
2 separate Web servers running a web application (load balanced)
1 separate server running XSockets v3.06 (as a Windows Service)
All servers are in a sub domain:
a. Web server: web1.acme.com
b. Xsocket Server: commbus.acme.com
(Note: I’m not showing the real domain name here (acme))
All servers are using the same wildcard certificate “cn=*.acme.com”
All servers are behind a firewall.
I’ve tried using a ConfigurationSettings class with the following different constructors:
(Note: the 192.168.1.1 is not the real internal IP we use but it’s similar)
1) I used this option because it worked in the test environment
public class SecureConfig : ConfigurationSetting
{
public SecureConfig()
: base()
{}
}
2)
public SecureConfig()
: base(new Uri("wss://commbus.acme.com:4502"), new Uri("wss://192.168.1.1:4502"))
{
this.CertificateLocation = StoreLocation.LocalMachine;
this.CertificateSubjectDistinguishedName = "cn=*.acme.com";
}
3)
public SecureConfig()
: base(new Uri("wss://commbus.acme.com:4502"), new Uri("wss://192.168.1.1:4502"))
{
4)
public SecureConfig()
: base(new Uri("wss://commbus.acme.com:4502")
{}
5)
public SecureConfig()
: base(new Uri("wss://commbus.acme.com:4502")
{
this.CertificateLocation = StoreLocation.LocalMachine;
this.CertificateSubjectDistinguishedName = "cn=*.acme.com";
}
Test environment:
To verify that I can setup wss://. I’ve been able to do the following test:
1) Run IIS Express locally with HTTPS
2) Run the XSockets code in a console application
(Note: All XSockets code is in a separate library assembly and the same library assembly is used in both my test console application and production)
3) For the test I used the certificate “cn=localhost”
This worked fine if I used the following in a ConfiguationSetting Class:
public class SecureConfig : ConfigurationSetting
{
public SecureConfig()
: base()
{
}
}
Behavior I’ve notice with the testing site:
I would get the same error in production if I used the following contructors for the ConfigurationSettings class:
public SecureConfig()
: base(new Uri("wss://localhost:4502"))
{
}
Or
public SecureConfig()
: base(new Uri("wss://localhost:4502"))
{
this.CertificateLocation = StoreLocation.LocalMachine;
this.CertificateSubjectDistinguishedName = "cn=local";
}
I’m not sure what I’m missing.

I was able to get it working.
I had to load the certificate from the file system.
public class SecuritConfig: ConfigurationSetting
{
public SecureConfig():base(new Uri("wss://commbus.acme.com"), new Uri("wss://192.168.1.100"))
{
this.Certificate = new X509Certificate2("wildcard.acme.com.pfx", "pwd");
}
}

Related

Elsa workflow designer errors

I have completed the below tutorial to correctly configure a working elsa server
Part 2 of Building Workflow Driven .NET Applications with Elsa 2
I made modifications for running it with docker-compose allong with the dependant services.
Everything works as expected except the intellisense in the designer window.
Ive noticed a couple of errors in the browser console as below
this is my startup class
public class Startup
{
public Startup(IConfiguration configuration, IWebHostEnvironment environment)
{
Configuration = configuration;
Environment = environment;
}
private IConfiguration Configuration { get; }
private IWebHostEnvironment Environment { get; }
public void ConfigureServices(IServiceCollection services)
{
var dbConnectionString = Configuration.GetConnectionString("Sqlite");
// Razor Pages (for UI).
services.AddRazorPages();
// Hangfire (for background tasks).
AddHangfire(services, dbConnectionString);
// Elsa (workflows engine).
AddWorkflowServices(services, dbConnectionString);
// Allow arbitrary client browser apps to access the API for demo purposes only.
// In a production environment, make sure to allow only origins you trust.
services.AddCors(cors => cors.AddDefaultPolicy(policy => policy.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin().WithExposedHeaders("Content-Disposition")));
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app
.UseStaticFiles()
.UseCors(cors => cors
.AllowAnyHeader()
.AllowAnyMethod()
.SetIsOriginAllowed(_ => true)
.AllowCredentials())
.UseRouting()
.UseHttpActivities() // Install middleware for triggering HTTP Endpoint activities.
.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers(); // Elsa API Endpoints are implemented as ASP.NET API controllers.
});
}
private void AddHangfire(IServiceCollection services, string dbConnectionString)
{
services
.AddHangfire(config => config
// Use same SQLite database as Elsa for storing jobs.
.UseSQLiteStorage(dbConnectionString)
.UseSimpleAssemblyNameTypeSerializer()
// Elsa uses NodaTime primitives, so Hangfire needs to be able to serialize them.
.UseRecommendedSerializerSettings(settings => settings.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb)))
.AddHangfireServer((sp, options) =>
{
// Bind settings from configuration.
Configuration.GetSection("Hangfire").Bind(options);
// Configure queues for Elsa workflow dispatchers.
options.ConfigureForElsaDispatchers(sp);
});
}
private void AddWorkflowServices(IServiceCollection services, string dbConnectionString)
{
services.AddWorkflowServices(dbContext => dbContext.UseSqlite(dbConnectionString));
// Configure SMTP.
services.Configure<SmtpOptions>(options => Configuration.GetSection("Elsa:Smtp").Bind(options));
// Configure HTTP activities.
services.Configure<HttpActivityOptions>(options => Configuration.GetSection("Elsa:Server").Bind(options));
// Elsa API (to allow Elsa Dashboard to connect for checking workflow instances).
services.AddElsaApiEndpoints();
}
}
this is my docker compose
version: '3.4'
services:
workflow.web:
image: ${DOCKER_REGISTRY-}workflowweb
ports:
- 5000:80
- 5001:443
build:
context: .
dockerfile: src/Workflow.Web/Dockerfile
networks:
- testnet
email.service:
image: rnwood/smtp4dev:linux-amd64-3.1.0-ci0856
ports:
- 3000:80
- "2525:25"
networks:
- testnet
elsa.dashboard:
image: elsaworkflows/elsa-dashboard:latest
ports:
- "14000:80"
environment:
ELSA__SERVER__BASEADDRESS: "http://localhost:5000"
networks:
- testnet
networks:
testnet:
driver: bridge
Any ideas
Most likely the issue is that the docker image for the dashboard is not compatible with the workflow server hosted by your application.
The cause of this mismatch is that the blog post references Elsa 2.3 NuGet packages, while the dashboard docker image is built from the latest source code in the master branch (which is something that should be fixed to avoid confusion like you're experiencing).
To make the dashboard work (which is built against latest source code), you need to update your workflow server app to reference the latest Elsa preview packages from MyGet (which are also built against latest source code from the master branch).
The following documentation describes how to reference the MyGet feed: https://elsa-workflows.github.io/elsa-core/docs/next/installation/installing-feeds#myget

An error occurred applying migrations, try applying them from the command line

I am on visual studio 2019 for mac running a blazor server app with .net core 3.1 and Individual Authentication (In-app) turned on.
When i go to register and enter new users details i am presented with the following error when clicking the apply migrations button
In the appsettings.json i have the following set.
{
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Database=Test; user=SA; password=P#55word; Trusted_Connection=False;"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
Startup.cs
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using CMUI.Areas.Identity;
using CMUI.Data;
namespace CMUI
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = false)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<IdentityUser>>();
services.AddSingleton<WeatherForecastService>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
}
}
The the SQL server i am running is 2019 mssql in docker using the following command
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=P#55word' -p 1433:1433 -d --name=mssqlserver2019 mcr.microsoft.com/mssql/server:2019-latest
The database is working okay as i can perform crud actions via an webapi in another solution using the same connection string. Not sure if this is a mac thing or if i have missed something silly.
Thanks.
You can try using the command line and navigating to the project root of the project that connects to that db, and then running dotnet ef database update which should run that migration and build your identity tables. Then fire the app up again and as long as it's connecting (which is looks like you are) you should be able to register users.
Further reading on migrations here. You may need to install the command line tools mentioned in this article.
I'm not familiar with VS for MacOS, but in the windows version you can go to Package Manager Console, make sure the default project in the console is set to your DB access project, and then run the command update-database. This might work for you as well.

App running in Android Emulator fails to perform an HTTP Post to localhost

I'm unable to perform an HTTP Post with an app running in an Android Emulator.
{StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content:
System.Net.Http.HttpConnection+HttpConnectionResponseContent, Headers:
{ Server: Microsoft-HTTPAPI/2.0 Date: Wed, 23 Oct 2019 00:58:01
GMT Connection: close Forwarded: host=XXX.XXX.X.XX:XXXXX;
proto=https Content-Type: text/html; charset=us-ascii
Content-Length: 374 }}
Setup:
I'm using an IP address generated by Conveyor by Keyoti
I installed a security certificate on the emulator required by Conveyor by Keyoti
I swapped out Microsoft.AspNetCore.Mvc.HttpPost attribute with System.Web.Http.HttpPost
Emulator:
Successful: HTTP Get
Failed: HTTP Post
Integration Test:
Successful: HTTP Post (using same endpoint)
Code:
I wrote an automated test that calls the same HTTP Post implementation.
Because I executed the same code successfully on my laptop via an automated test, I don't think the actual code is the issue:
open Microsoft.AspNetCore.Mvc
open Newtonsoft.Json
[<ApiController>]
[<Route("api/[controller]")>]
type RegisterController () =
inherit ControllerBase()
[<System.Web.Http.HttpPost>]
member x.Post([<FromBody>] json:string) =
...
Summary:
In conclusion, I have isolated the environment to the Android Emulator and not my laptop. Hence, the emulator can successfully trigger an HTTP Get. However, it fails to perform a HTTP Post even though my laptop device can do both.
UPDATE:
I applied guidance from this Xamarin Android ASP.Net Core WebAPI document.
Specifically, I installed another security certificate on the Android emulator.
I was then able to observe an HTTP Get on the Android Emulator.
However, I continue to get an error for HTTP Post.
OperationCanceledException
Physical Device:
If I run the app from a physical android device I observe the following:
{StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.HttpConnection+HttpConnectionResponseContent, Headers:
{
Date: Wed, 23 Oct 2019 13:33:20 GMT
Server: Kestrel
Transfer-Encoding: chunked
Forwarded: host=xxx.xxx.x.xx:xxxxx; proto=https
Content-Type: text/plain
}}
New Update:
I disabled debugging on just my code on the server implementation and discovered the following exception:
Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException: 'Bad chunk size data.'
Any suggestions?
this might not be a direct answer to your question, but i would like to suggest
localtunnel. a very easy way to temporarily expose your local api so that you can test it either on emulator or even physical device. Have used this alot my self, as it is very convenient to just type a single line in terminal to start it.
The following reference solved my issue.
Infrastructure:
type GlobalHttpClient private () =
static let mutable (httpClient:System.Net.Http.HttpClient) = null
static member val Instance = httpClient with get,set
Xamarin.Android project:
using Android.Http;
using Android.Net;
using Javax.Net.Ssl;
using System.Net.Http;
using Xamarin.Android.Net;
using Xamarin.Forms;
using WebGatewaySupport;
[assembly: Dependency(typeof(HTTPClientHandlerCreationService_Android))]
namespace Android.Http
{
public class HTTPClientHandlerCreationService_Android : IHTTPClientHandlerCreationService
{
public HttpClientHandler GetInsecureHandler()
{
return new IgnoreSSLClientHandler();
}
}
internal class IgnoreSSLClientHandler : AndroidClientHandler
{
protected override SSLSocketFactory ConfigureCustomSSLSocketFactory(HttpsURLConnection connection)
{
return SSLCertificateSocketFactory.GetInsecure(1000, null);
}
protected override IHostnameVerifier GetSSLHostnameVerifier(HttpsURLConnection connection)
{
return new IgnoreSSLHostnameVerifier();
}
}
internal class IgnoreSSLHostnameVerifier : Java.Lang.Object, IHostnameVerifier
{
public bool Verify(string hostname, ISSLSession session)
{
return true;
}
}
}
Xamarin.Forms App:
switch (Device.RuntimePlatform)
{
case Device.Android:
GlobalHttpClient.Instance = new HttpClient(DependencyService.Get<IHTTPClientHandlerCreationService>().GetInsecureHandler());
break;
default:
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
GlobalHttpClient.Instance = new HttpClient(new HttpClientHandler());
break;
}
Client Gateway:
let postTo (baseAddress:string) (resource:string) (payload:Object) =
GlobalHttpClient.Instance.BaseAddress <- Uri(baseAddress)
let encoded = Uri.EscapeUriString(resource)
let result = GlobalHttpClient.Instance.PostAsJsonAsync(encoded, payload) |> toResult
result
Looks like you have a .NET Core Api. .NET Core does not have System.Web in Asp.NET. The HttpPost attribute and HttpGet attributes should come from Microsoft.AspNetCore.Mvc namespace which you have open.
Also since you are using the ApiController attribute model binding will just work as long as you bind to a model and not just a json string.
Create a model that you want the json to bind to and use that type for your parameter on Post and remove the FromBody attribute. Also if you do that you probably don't need newtonsoft.json.
open Microsoft.AspNetCore.Mvc
[<ApiController>]
[<Route("api/[controller]")>]
type RegisterController () =
inherit ControllerBase()
[<HttpPost>]
member x.Post(thing:TypeOfThing) =

Cache plugin not caching

Could some wise guru give me a hand to get the Cache Plugin to work? I have been given this project that uses:
Grails 3.3.0
gradle 3.0
GORM 6.1.6.Release
Cache Plugin 4.0.0
I'm following https://grails-plugins.github.io/grails-cache/snapshot/guide/index.html#usage to enable Caching though the app can be started without error, the method that is annotated by #Cacheable doesn't seem to be caching. This is what my myWebApp**build.gradle** looks like:
:
compile group: 'org.grails.plugins', name: 'cache', version: '4.0.0'
compile group: 'org.grails.plugins', name: 'async'
:
This is my grails-app/conf/application.yml:
---
grails:
cache:
caches:
name: 'mycache'
---
This is how I enable cache in grails-app/conf/application.groovy:
:
grails.cache.enabled = true
grails.cache.clearAtStartup = true
:
This is my myWebApp/Application.groovy:
package myWebApp
:
class Application extends GrailsAutoConfiguration {
static void main(String[] args) {
GrailsApp.run(Application, args)
}
}
This is the method in a controller with #Cachable (grails-app/controllers/data/mycontroller.groovy):
package data
:
import org.springframework.cache.annotation.Cacheable
:
#Transactinal
class MyController {
:
#Cacheable(value='mycache')
def getSomeId() {
return anId
}
:
}
In the same controller, I am calling this method for quick test:
:
def index() {
def id = getSomeId()
:
}
:
The problem is getSomeId() didn't seem to be cached. Everytime getSomeId() was called, the body was executed in full length (I set a break point to verify). I just want to use a quick and simple cache mechanism for simple things like this.
What did I do wrong?
Thanks for all you folks, the cache finally works in my project. HOWEVER, the import for annotation must come from the plugin: grails.plugin.cache.Cacheable works, but org.springframework.annotation.Cacheable doesn't.

Ionic: Error: Module build failed: Error: ENOENT: no such file or directory

I am using Ionic, and get the following error:
Runtime Error Uncaught (in promise): Error: Module build failed:
Error: ENOENT: no such file or directory, open
'/Users/richardmarais/Development/ionic/theWhoZoo/src/pages/model/ratingModel.js'
The error is a result of this line of code:
this.ratingModel = new RatingModel();
When I remove this line, I don't get the error.
ratingModel.ts
import { Injectable } from "#angular/core";
import { PersonModel } from './personModel';
import { JobModel } from './jobModel';
#Injectable()
export class RatingModel {
public id: number = null;
public job: JobModel = null;
public review: string = null;
public rating: number = null;
public reviewDate: number = null;
public time: string = null;
public person: PersonModel = null;
public anonymous: number = null;
constructor() {
}
}
Reading other forums, people are getting this error due to the case not matching in their imports, but I have checked mine, and they do match.
import { RatingModel } from '../model/ratingModel';
However, I have noticed something strange in my IDE (Visual Studio Code):
As you can see, in the search results, there are two files for the object, ratingModel.ts and RatingModel.ts. But when I check the actual files system, there is only on file, ratingModel.ts:
Question
Does anyone know what and how to resolve what looks like possibly a bug or fault here?
Thanks
More info:
global packages:
#ionic/cli-utils : 1.0.0
Cordova CLI : 6.4.0
Ionic CLI : 3.0.0
local packages:
#ionic/app-scripts : 1.3.0
#ionic/cli-plugin-cordova : 1.0.0
#ionic/cli-plugin-ionic-angular : 1.0.0
Ionic Framework : ionic-angular 3.2.1
System:
Node : v7.10.0
OS : macOS Sierra
Xcode : Xcode 8.3.2 Build version 8E2002
ios-deploy : not installed
ios-sim : not installed
Apologies, my bad. I just found another file that was importing the object with the incorrect case. It does appear as if there is no issue, and I had a bug in my code.
import { RatingModel } from '../model/RatingModel';
This error occurred when your component can't be found with your app.module settings.
Follow these steps to solve your problem:
Right click on your web browser and select inspect (in this case I use chrome)
In the source tab, navigate to localhost:8100 (the default port for running ionic)
Go to src -> pages and open corresponded page(in this case 'model')
The name of .ts file and path must be as same as the name and path of the added import path in app.module.ts
In this case, there isn't model/ratingModel.ts
be aware :
The path is case sensitive (maybe the .ts file is RatingModel)

Resources