Saturday, 9 January 2021

Trials of WCF clients and .NET Core 3.1

 I've spent four days debugging a simple WCF problem. We had a WCF server that we needed to connect to. That server required WSSE username/password security, as you can see from various excerpts in the WSDL:


    
        
            
                
            
        
    

And from a working client, I could see that a good SOAP message looked like this:


    
        
            
                2021-01-09T08:50:59.443Z
                2021-01-09T08:55:59.443Z
            
            
                MyUsername
                MyPassword
            
        
    
    
            My Body goes here
    
Initially I went on a whole route of writing code to create the necessary SOAP header.

A great article is described here:

The bugs I encountered where:

The header 'Security' from the namespace 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd' was not understood by the recipient of this message, causing the message to not be processed.

In the end I discovered the simplest implementation was the correct one and no overrides were required. But a bug was still found.  I was getting the error:

The value 'TransportWithMessageCredential' is not supported in this context for the binding security property 'securityMode'.

The solution was found here:

c# - Why TransportWithMessageCredential is not supported in .net core? - Stack Overflow

Even though I created a new .NET Core 3.1 client, the default ServiceModel packages installed were version 4.4, and upgrading them to 4.8 allowed me to set BasicHttpsSecurityMode.TransportWithMessageCredential.


Final code

var endpointAddress = new EndpointAddress(uri);
var binding = new BasicHttpsBinding();
binding.Security.Mode = BasicHttpsSecurityMode.TransportWithMessageCredential;
var client = new StartSessionServiceClient(binding, endpointAddress);
client.ClientCredentials.UserName.UserName = "MyUsername";
client.ClientCredentials.UserName.Password = "MyPassword";
var response = await client.StartSessionAsync(new SessionStartArgs());


References

WCF WS-Security and WSE Nonce Authentication - Rick Strahl's Web Log (west-wind.com)



The value 'TransportWithMessageCredential' is not supported in this context for the binding security property 'securityMode'. - .NET Core 3.1

I had an .NET Core 3.1 WCF client trying to connect to a WCF service over HTTPS, passing a username and password using WSE Security.

Writing the client code:

var binding = new BasicHttpsBinding();
binding.Security.Mode = BasicHttpsSecurityMode.TransportWithMessageCredential;

I was getting the error:

The value 'TransportWithMessageCredential' is not supported in this context for the binding security property 'securityMode'.

This was because the default project installed System.Service model assemblies, version 4.4. Upgrading them to 4.7 or higher fixes this.

Monday, 4 January 2021

Surface Pro 4 monitor woes with a Dell 2515H

 Occassionally my monitor would show a very low resolution and I was unable to set it back to a high resolution as they were unavailable in Windows.

This article pointed me to this Dell article.

Changing the monitor configuration to DP Version 1.2 fixed the problem.

Saturday, 2 January 2021

Startup apps in Windows 10

https://www.msftnext.com/manage-windows-10-startup-apps/

1. Task Manager

2. Startup folder:

C:\Users\<User>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

or %appdata%\Microsoft\Windows\Start Menu\Programs\Startup

3. Registry

Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

and

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

4. Store app startup

Settings - Apps - Startup

5. Task Scheduler


Tuesday, 29 December 2020

Open Source HTML to PDF converter

The software I inherited included a function for converting an HTML quote into a PDF.

It used a library from a 3rd party vendor, Winnovative Software. As I was re-hosting the server from IaaS to Azure App Services, I found that the library didn't work under the sandboxed App Service environment.

A different component was required, but it was covered under my license. But then I discovered that my license was for V14 and the new version was V15.

Could I download the previous version - the one I paid for? No. "It was over 2 years old" the company told me. They no longer provided download links. I would have to pay to upgrade.

So 2 years old is deemed too old to support now. And I would have to pay to get the later version to get features I didn't need nor want.

I thought this was rather unfair practice and so I did some more research.

And I stumbled across the excellent open source wkhtmltopdf tool. And even better, Adam Hockemeyer provided a docker image that did exactly what I needed - it hosted the tool as a .NET Core Web service in Azure App Service.

Max Kudos to Adam - you saved me hours and hours of effort, and prevented me rewarding bad support behaviour.

Wednesday, 23 December 2020

ASP.NET Core: FileNotFoundException: Could not load file or assembly

 I had a complex solution with multiple projects and NuGet references.

To debug one troublesome Nuget package, I removed the Nuget reference and added a project reference so I could step through the code.

However when the website ran, it would throw the error:

FileNotFoundException: Could not load file or assembly <troublesome assembly>

Investigation

  1. procmon.exe indicated that the website wasn't even loading the assembly - or trying to
  2. <website>.deps.json didn't have a reference to the assembly
  3. Visual Studio Resharper was showing the following popup:


Conclusions

The problem was that I had added the project to the solution, but the project was located in a folder outside of the root solution folder. By taking a copy inside of the root solution folder and re-adding the reference, the <website>.deps.json then included the reference and the assembly loaded.

  1. Check your <website>.deps.json 
  2. Use ProcMon
  3. Make sure that the project referenced is inside your solution folder.


Tuesday, 24 November 2020

Move To iOS - transfer interrupted problem

A common problem described on the reviews of the "Move to iOS" app is that people are being constantly disconnected when transferring files and settings.

FIXED THE TRANSFER INTERRUPTED PROBLEM

What is happening is your Android connects to a local hotspot created on the iPhone. You will notice that the Wifi indicator on the Android has an exclamation mark. This is because it detects it cannot reach the internet, so it disconnects and tries your home LAN again.


Go to Network Settings and FORGET YOUR EXISTING WIFI connections so it cannot reconnect to your home wifi. Then it is forced to stay on the iPhone hotspot.