Problems connecting to WCF service

Trying to connect to a WCF-service but get some error messages:

The HTTP request is unauthorized with client authentication scheme Anonymous The authentication header received from the server was Basic

The provided URI scheme https is invalid expected http

The solution was to adjust web.config > system.serviceModel section. Add “Transport” to security mode. and clientCredentialType should be “Basic” if the server expects Basic Realm.

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="Document_Binding" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00" maxReceivedMessageSize="2147483647">
          <security mode="Transport">
            <transport clientCredentialType="Basic" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
    <endpoint ....../>
    </client>
  </system.serviceModel>

Good luck with your connections =)

Unable to connect to SQL DB via SSMS on Azure VM

I’ve installed SQL Server 2016 Express on a Azure Virtual Machine (VM). I opened the ports (port 1433) to connect to the server via Sql Server Management Studio (SSMS) but access was denied. I also opened the port inside the Azure portal on the server but still no success.
Then I came over a solution to the connection problem. You need to set the port number on IPAll among IP Addresses inside TCP/IP in Sql Server Configuration Manager. See screenshot below.

sql-server-ip-address
TCP Port 1433

How to navigate to the TCP Port setting:

  1. Open Sql Server Configuration Manager.
  2. Click on “Protocols” for “{INSTANCE NAME}” under Sql Server Network Configuration.
  3. Double click on TCP/IP.
  4. Click on tab “IP Addresses”.
  5. Scroll to the bottom and write the port number (1433 is default).

Good luck!

Copy files using a runtime created batch file C#

If you would like to copy one or several files using a batch file. The command for that is “copy {target} {destination}”. It’s also possible to use wildcards i.e “copy *.txt c:\temp”.
To create a bat (batch) file on runtime and then execute the file you could write something like this in C#.


string batchFileName = @"C:\{filePath}\copy.bat";
System.IO.File.WriteAllText(batFileName, @"copy {fileName}.{extension} {destination-filePath}");
System.Diagnostics.Process.Start(batFileName);

sqlI have a table in Microsoft SQL Server where insert or updates isn’t possible. Table is only responsible to increment a unique id.

The table looks like this:

CREATE TABLE [dbo].[CustomerOrderNumbers](
[customerOrderNumberId] [int] IDENTITY(1,1) NOT NULL,
[createdOn] [datetime] NOT NULL,
[isDeleted] [bit] NOT NULL,
PRIMARY KEY CLUSTERED
(
[customerOrderNumberId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[CustomerOrderNumbers] ADD DEFAULT (getdate()) FOR [createdOn]
GO

ALTER TABLE [dbo].[CustomerOrderNumbers] ADD DEFAULT ((0)) FOR [isDeleted]

But how do you increase the primary key when you can’t insert any values?

Answer, insert default value:
INSERT INTO [CustomerOrderNumbers] DEFAULT VALUES

This command also works with Azure SQL database.

Cordova build APK – Package damaged

I tried to build an APK (Android) in Cordova, build is successful so far so good!
When transferring the file to my mobile I got error message during install “Installation is not possible, package is damaged”. I created a new Cordova project and compared my “config.xml” file with the one in the project that failed. Found out that the “android-versionCode” is causing the problem. This is specified in the top of the config.xml. Remove that and the install is successful!

Use only Swedish servers in tor browser

If you want to use only Swedish servers in Tor browser (or any other country) to connect on you can do it like this:
1. Open the file “torrc” at “Tor Browser\Browser\TorBrowser\Data\Tor\”.

2. Add line “ExitNodes {countryCode}”.
You can use country code se for swedish, gb or us for english and so on) at end of the file.
3. Save the file and restart the browser.

 

Unable to launch the IIS Express Web server

Unable to launch the IIS Express Web server.
Output from IIS Express. Failed to register URL for site. The format of the specified network name is invalid 0x800704BE.

The error occured beacause I had a IP binding to 192.168.0.50 added with: “netsh http add iplisten 192.168.0.50”

To remove IP-binding you can use the following command (requires admin permission)

1. Remove current ip listening: netsh http delete iplisten {ip-address}
2. Listen to all ip addresses: netsh http add iplisten 0.0.0.0

Export PFX file from CRT/CER/P7B

Certificate handling. If you want to export a PFX file from a .CRT, .CER or .P7B file, follow these steps:

1. Install Windows 10 SDK (https://developer.microsoft.com/sv-se/windows/downloads/windows-10-sdk).

2. Navigate to folder: C:\Program Files (x86)\Windows Kits\10\bin\10.0.16299.0\x64.

3. Start “certmgr.exe”.

4. In the window that opens you will se a list of all the certificates that are installed. Select the certificate you want export. The click on the button “Export”.

5. Follow the Export Wizard. You will now be able to select export as a PFX file.

Could not load file or assembly System.Web.WebPages.Razor

Suddenly got the error message when starting a MVC application:

Could not load file or assembly ‘System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly ‘System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified.

[FileNotFoundException: Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   System.Web.Mvc.PreApplicationStartCode.Start() +0

[InvalidOperationException: The pre-application start initialization method Start on type System.Web.Mvc.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..]
   System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +615
   System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +141
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +102
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +157
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +549

[HttpException (0x80004005): The pre-application start initialization method Start on type System.Web.Mvc.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10085804
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +95
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

Solution

Run following command in the package manager console:
Update-Package Microsoft.AspNet.Mvc -Reinstall