Wednesday, February 23, 2011

WIF : Self signed certificates

With WIF and ADFS, certificates cause endless problems.

The solution for IIS 7 is to use SelfSSl7.

It's a command line application e.g.

USAGE:
SELFSSL7.EXE [/N cn=name] [/K size] [/V days] [/T] [/I] [/S name] [/A I
PAddress] [/P port] [/X] [/F file] [/W password] [/Q]

CERTIFCATE PARAMETERS:
/N name Specifies the common name(s) of the certificate.
Computer name is used if not specified.
Example: /N cn=m1.contoso.com or /N cn=m1.contoso.com;cn=m2.contoso.com
/K size Specifies the key length. Default is 1024.
/V days Specifies the validity of the certificate in days.
Default is 30 days.

TRUST PARAMETERS:
/T Adds the self-signed certificate to user's "Trusted Certificates" list.

IIS PARAMETERS:
/I Add SSL binding to IIS.
Use with the following parameters:
/S name Specifies the name of the site. Default is "Default Web Site".
/A IP Specifies the IP address for the IIS binding. Default is *.
/P port Specifies the SSL port. Default is 443.

EXPORT PARAMETERS:
/X Export certificate to PFX file.
Use with the following parameters:
/F PFX file location.
/W password for PFX file.

OTHER PARAMETERS:
/Q Overwrites existing SSL binding and/or PFX file.

The default behavior is equivalent with:
selfssl7.exe /N cn="machine name" /K 1024 /V 30
/I /S "Default Web Site /P443 /A * /T


I normally use:

SelfSSL7 /V 90 /Q /X /F c:\xxx\Cert.pfx /W password /T

Enjoy!

ADFS : Re-installing ADFS v2.0

Had a number of problems with this so decided to remove ADFS and re-install.

Un-installed it via Control Panel, removed the web site from IIS (Default Web Site) and deleted the adfs directory under inetpub.

When I ran the wizard again, all components correctly installed but the wizard complained that it found the web site so could not re-install. The message was "Existing web site detected".

WTF - I removed everything.

Mr. Google to the rescue and eventually I found the solution.

You need to run the command:

"appcmd delete app "Default Web Site/adfs/ls"

and

"appcmd delete app "Default Web Site/adfs/card"

"appcmd" runs under the command prompt and is found under "C:\Windows\System32\inetsrv".

Enjoy!

Friday, February 04, 2011

LINQ : LINQPad sample not a valid zip file

Under the Samples tab in LINQPad, you can download more samples.

When I clicked this, I got an error telling me that the file in ...\AppData\Local\Temp\LINQPad was not a valid zip file.

WTF?

So I ran up the estimable Fiddler in order to see what was happening and when I tried it, it all worked!

Somehow, putting Fiddler in the middle fixes the problem.

Bizarre, but alls well that ends well!

Enjoy!

Friday, January 21, 2011

WIF : Problems with SecurityTokenVisualizerControl

This control shows the token information for WIF / ADSL v2.

The control can be downloaded from Security Token Visualizer Control.

The problem is that the wizard looks for Visual Studio 2008. I have Visual Studio 2010 but the wizard doesn't think that's good enough!

Also, it tells me that I don't have the WIF SDK installed. Actually, I do!

Workaround:

Once you've installed the download, don't bother with the wizard - it requires VS 2008 etc.

Navigate to:

C:\IdentityTrainingKit2010\SecurityTokenVisualizerControl\code\Microsoft.Samples.DPE.Identity.Controls

or wherever you installed it and then open:

Microsoft.Samples.DPE.Identity.Controls.csproj

in VS.

You'll have to convert it from an older standard (just reply "Yes" to the question).

Then build it. You now have a .dll in the \bin directory.

Add this .bin to the Toolbar viz. Right click on Toolbar - "Add Tab" - give it a name like "Security Token Visualizer Control".

Then right-click on the new tab - "Choose Items" and browse to the .dll.

The control will now be in your toolbar ready to be dragged onto your page.

Remember to add saveBootstrapTokens="true" to the web.config.

Enjoy!

Thursday, January 13, 2011

WCF : Could not find default endpoint element that references contract

Working through the WCF samples, I came across the in-line calculator.

Built it according to the instructions (using Visual Studio 10 and .NET Framework 4), ran it up and got the following exception:


Could not find default endpoint element that references contract 'ICalculator' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.


A lot of communication with Mr. Google and then came across a comment way down in a blog entry that offered some hope.

To generate the proxies, you run:


svcutil.exe http://localhost/IISHostedCalc/service.svc?wsdl


This generates two files:

CalculatorService.cs
output.config

and you add them to your project using "Add Existing Item".

To get rid of the exception, simply rename "output.config" to "app.config" and ensure it is part of your project.

Enjoy!

Tuesday, December 21, 2010

Visual Studio : Counting lines of code

Had a look at a vb application to get a feeling for how much work it would take to support it.

One of the measures of complexity is "lines of code" (LoC). Yes, I know it's a crap measure but it's better than nothing and a useful guide.

Mr. Google to the rescue and (no surprise), a good answer on Stackoverflow.

So downloaded the code from here and installed it.

Warning - I had to open and close the project a few times before I could get it to "take" but I got it working and I found that it was a really useful tool.

Hasn't been updated for ages so very much in the Visual Studio 2003 / 2005 era but luckily that was the ballpark I was in.

Enjoy!

Wednesday, December 08, 2010

Visual Studio : Unable to make the session state request

I was running up Visual Studio for an ASP.NET project when I got this error:

"Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same. If the server is on a remote machine, please ensure that it accepts remote requests by checking the value of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters\AllowRemoteConnection."

Mr. Google to the rescue and you have to start up:

Control Panel / Administrative Tools / Services.

Right click on ASP.NET State Service / Start



Refresh the browser and you're good to go.

Enjoy!

Friday, November 26, 2010

Web services : cURL

If you need to do some web service client testing, there are a number of tools like SOAPUI but they all involve installing programs etc.

Then I came across this neat tool cURL

To quote from the docs:

"curl is a command line tool for transferring data with URL syntax, supporting DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, TELNET and TFTP. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, kerberos...), file transfer resume, proxy tunneling and a busload of other useful tricks."

It runs on a wide variety of platforms.

So how do you use it to test a web service?

You need to mock-up what the actual SOAP packet looks like e.g.

to test a web service called TestWS, the information might look like:






123456
Joe
Bloggs





Save this in a file called TestWS.xml.

The command line for cURL would then be:

curl --data @TestWS.xml --header "Content-Type: text/xml" --header "Accept-Encoding: gzip,deflate" --verbose http://host:port/TestWSService


This then sends the HTTP POST which itself contains a SOAP message which invokes the web service.

The verbose option prints out both the request and the response.

Enjoy!

Tuesday, November 23, 2010

Netbeans : Providing command line arguments inside Netbeans

I write a lot of command line Netbeans (6.9) Java programs. A lot of them take command line arguments e.g.


java Program Option1 Option2


and you access them from "String[] args".

When you are running inside Netbeans, you need to provide the arguments by:

Right click the project / Properties / Run / Arguments

If you right click the Java file you are testing (the Main class) and select "Run File" the program runs but ignores the configured arguments.

To get around this, you have to right click the project and select "Run".

Enjoy!

Java : Checking if environment variables are valid

Has a few problems with environment variables and I couldn't find a utility that would check them for me e.g. checking if all the entries in my PATH environment variable were valid.

So I rolled my own:


public class CheckEnv {

/**
* @param args the command line arguments
*/
static String envVar = "";
static String envValue = "";
static String envValueStrings[];
static String envValueString = "";
static boolean valid = false;

public static void main(String[] args) {
// TODO code application logic here

if (args.length < 1) {
System.out.println("\nUsage is 'java -jar CheckEnv.jar '");
System.out.println();
System.out.println(" e.g. 'java -jar CheckEnv.jar PATH'");
System.out.println(" 'java -jar CheckEnv.jar CLASSPATH'");
System.out.println(" 'java -jar CheckEnv.jar INCLUDE'");
System.out.println(" 'java -jar CheckEnv.jar LIB'");
System.exit(1);
}

envVar = args[0];

envValue = System.getenv(envVar);

System.out.println ("\nChecking for environment variable " + envVar + "\n");

if (envValue == null)
{
System.out.println ("Environment variable " + envVar + " doesn't exist");
System.exit(1);
}

envValueStrings = envValue.split(";");

for (int i = 0; i < envValueStrings.length; i++) {
envValueString = envValueStrings[i];

System.out.print("Checking " + envValueString + " ");

File file = new File(envValueString);
valid = file.exists();

if (valid) {
System.out.println("- variable exists");
} else {
System.out.println("- variable does not exist : WARNING");
}

}
}
}



Usage is 'java -jar CheckEnv.jar '

e.g. 'java -jar CheckEnv.jar PATH'
'java -jar CheckEnv.jar CLASSPATH'
'java -jar CheckEnv.jar INCLUDE'
'java -jar CheckEnv.jar LIB'


The output looks like e.g.


Checking C:\Program Files\Java\jdk1.6.0_22\jre\bin - variable exists
Checking C:\Program Files\Reflection - variable exists
Checking C:\Perl\bin\ - variable exists


Enjoy!

Monday, November 22, 2010

JMeter : IOException: Exceeded maximum number of redirects: 5

Using the JMeter proxy server to record and playback some logins to a site and got this error.

Mr. Google to the rescue and the trick is to modify the jmeter.properties file in the JMeter bin directory.


# Maximum redirects to follow in a single sequence (default 5)
httpsampler.max_redirects=20


Modify the above line in that file to increase the maximum from the default of 5. In my case, I found 20 to be adequate.

You need some kind of upper limit because otherwise the trace could just get stuck in a loop.

Note that you have to restart JMeter after making this change.

Enjoy!

Friday, November 19, 2010

Netbeans : SOAPUI plugin

Using Netbeans 6.9.

I wanted to download the SOAPUI plugin from soapUI NetBeans Plugin.

Although the description says "com-eviware-soapui-netbeans-module.nbm", when you actually download the file, you'll find it's a zip file.

Netbeans doesn't like loading zip files. A little research at Mr. Google shows that a .nbm file is essentially just a zip file with a different extension.

So I simply simply renamed

com-eviware-soapui-netbeans-module.zip to com-eviware-soapui-netbeans-module.nbm

and the plugin installed no problems at all.

It does warn you that the plugin is not signed but just ignore that and continue.

Enjoy!