Thursday, May 28, 2009

Empty Actions when mocking Java Web Service

I get the
System.InvalidOperationException: The operations methodX and methodY have the same action ().  Every operation must have a unique action value”, when trying to mock a Java Web Service with Rhino Mocks in CSharp.

The WSDL-file that was downloaded from the Java Web Service declared an empty soap action for each exported operation.
For example:

<operation name="aMethod">
  <soap:operation soapAction="" /> 
  <input>
   <soap:body use="literal" /> 
  </input>
  <output>
   <soap:body use="literal" /> 
  </output>
  <fault name="MyWebServiceException">
   <soap:fault name="MyWebServiceException" use="literal" /> 
  </fault>
</operation>

WCF uses the action to dispatch an incoming message to the correct method, see Action Property. Each method must have a unique action value.

I solved it by downloading the WSDL-file and remove all soap action declarations:

<soap:operation soapAction="" />

I ran the svcutil.exe on the changed WSDL-file.
WCF then creates unique action values in the service interface file, and the service can be mocked (as I described in Mocking WCF service).

Friday, May 15, 2009

Creating disconnected ADO Recordset in C#

I had some problems to create a disconnected ADO Recordset in C#. Finally I get it right.

public static Recordset CreateDisconnectedRecordset()
{
    // Create new recordset
    var rs = new Recordset();

    // Add some updatable fields
    rs.Fields.Append("name", DataTypeEnum.adVarChar, 20, FieldAttributeEnum.adFldUpdatable, Missing.Value);
    rs.Fields.Append("country", DataTypeEnum.adVarChar, 20, FieldAttributeEnum.adFldUpdatable, Missing.Value);

    // Open recordset
    rs.Open(Missing.Value, Missing.Value, CursorTypeEnum.adOpenUnspecified, LockTypeEnum.adLockUnspecified, 0);

    // Add data
    rs.AddNew(Missing.Value, Missing.Value);
    rs.Fields["name"].Value = "Anders";
    rs.Fields["country"].Value = "Sweden";
    rs.Update(Missing.Value, Missing.Value);

    return rs;
}

Monday, March 9, 2009

Continuous Integration Server Configuration

There are a few simple steps to set up a build server, but I always forget how and where I found the answer on the few problems that always pops up.

Here are the steps for building .NET 3.5 web-projects on a Windows 2008 server (using NAnt and NUnit):

Install:
  1. NAnt
  2. NUnit
  3. NCover
  4. NCoverExplorer (for fancy unit test coverage reports)
  5. .NET 3.5 Framework SDK
  6. CruiseControl.NET (or TeamCity)
Some special handling after installation:
  1. Open NAnt.exe.config and change the sdkInstallRoot value to a correct path.
    <readregistry
        property="sdkInstallRoot"
        key="SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.1\WinSDKNetFxTools\InstallationFolder"
        hive="LocalMachine"
        failonerror="false" />
  2. Create the C:\Program Files\MSBuild\Microsoft\VisualStudio\v9.0\WebApplications folder and copy the Microsoft.WebApplication.targets file from a computer with Visual Studio installed. (Used by Web Application Projects)