How to call a SOAP web service in .NET 4.0 C# without using the WSDL or proxy classes

If you want to call a .NET 4.0 C# web service, without using the WSDL or “Add Service Reference” in Microsoft Visual Studio 2010. You can use the following functions:

/// <summary>
/// Execute a Soap WebService call
/// </summary>
public override void Execute()
    HttpWebRequest request = CreateWebRequest();
    XmlDocument soapEnvelopeXml = new XmlDocument();
    soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:soap="""" xmlns:xsi="""" xmlns:xsd="""">
    <HelloWorld3 xmlns="""">
    using (Stream stream = request.GetRequestStream()) 

    using (WebResponse response = request.GetResponse())
        using (StreamReader rd = new StreamReader(response.GetResponseStream())) 
            string soapResult = rd.ReadToEnd();
/// <summary>
/// Create a soap webrequest to [Url]
/// </summary>
/// <returns></returns>
public HttpWebRequest CreateWebRequest()
    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(@""); 
    webRequest.ContentType = "text/xml;charset=\"utf-8\""; 
    webRequest.Accept = "text/xml"; 
    webRequest.Method = "POST"; 
    return webRequest; 


<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="" xmlns:xsi="" xmlns:xsd=""><soap:Body><HelloWorld3Response xmlns=""><HelloWorld3Result>test</HelloWorld3Result></HelloWorld3Response></soap:Body></soap:Envelope>


You can use complex types in you’re request. I use fiddler to get the contents of the soap envelope.

Logging key value pairs in a List<string>

If you have a List<string> with entries:

[0] = Parameter1.Name

[1] = Parameter1.Value

[2] = Parameter2.Name

[3] = Parameter2.Value

and want to convert this list to a string like Parameter1.Name = [Parameter1.Value] Parameter2.Name = [Parameter2.Value], you can use the following code:


/// <summary>
/// Convert a List of strings to a string in the format: Variable1.Name = [Variabel1.Value] Variable2.Name = [Variabel2.Value]
/// </summary>
/// <param name="variables">
/// Can't be null
/// Should have an evennumber of items
/// </param>
/// <returns></returns>
public static string GetFormattedLine(List<string> variables)
    StringBuilder result = new StringBuilder(string.Empty);

    if (variables == null)
        throw new ArgumentException(“Can't be null”, "variables");

    if (variables.Count % 2 != 0)
        throw new ApplicationException(string.Format(“[{0}] is not an evennumber”, "variabels.Count"));

    for (int i = 0; i < variables.Count; i++)
        if (i % 2 == 0)
            result.AppendFormat("{0} = [{1}] ", variables[i], variables[i + 1]);   

    return result.ToString().Trim();

Enabling Code Coverage in Visual Studio 2010


1. Open the local.testsettings which you can access from Test -> Edit Test Settings -> Local (local.testsettings)



2. Select Data and Diagnostics from the list


3. Check the enabled checkbox on the Code Coverage row

4. Click on the Configure button or double click the Code Coverage row

5. Select the assemblies you want code coverage to be generated for


Solving the Microsoft SQL Server Agent error: @schedule_uid is not a parameter for procedure sp_add_jobschedule.

I was getting the error @schedule_uid is not a parameter for procedure sp_add_jobschedule, when executing a  script that was generated by Microsoft SQL Server Management Studio.


This had something to do with Microsoft SQL Server 2005 vs Microsoft SQL Server 2008. On Microsoft SQL Server 2005 this parameter is @schedule_id and on Microsoft SQL Server 2008 this parameter is @schedule_uid (and from an other type)


But when you remove this parameter, the script will work on both SQL Server 2005 as on Microsoft SQL Server 2008

How to determine the folders used by a Microsoft Visual Studio unit test

You can use the directories used by a Microsoft Visual Studio unit test, by using the TestContext object.

public void GetUnittestFolders()
    Console.WriteLine(string.Format("CurrentTestOutcome [{0}]", TestContext.CurrentTestOutcome));
    Console.WriteLine(string.Format("DeploymentDirectory [{0}]", TestContext.DeploymentDirectory));
    Console.WriteLine(string.Format("ResultsDirectory [{0}]", TestContext.ResultsDirectory));
    Console.WriteLine(string.Format("TestDeploymentDir [{0}]", TestContext.TestDeploymentDir));
    Console.WriteLine(string.Format("TestDir [{0}]", TestContext.TestDir));
    Console.WriteLine(string.Format("TestLogsDir [{0}]", TestContext.TestLogsDir));
    Console.WriteLine(string.Format("TestRunDirectory [{0}]", TestContext.TestRunDirectory));
    Console.WriteLine(string.Format("TestRunResultsDirectory [{0}]", TestContext.TestRunResultsDirectory));




DeploymentDirectory [C:\Projects\ASF\Configurator\Main\TestResults\rLisdonk_L015 2011-01-19 08_27_21\Out]

ResultsDirectory [C:\Projects\ASF\Configurator\Main\TestResults\rLisdonk_L015 2011-01-19 08_27_21\In]

TestDeploymentDir [C:\Projects\ASF\Configurator\Main\TestResults\rLisdonk_L015 2011-01-19 08_27_21\Out]

TestDir [C:\Projects\ASF\Configurator\Main\TestResults\rLisdonk_L015 2011-01-19 08_27_21]

TestLogsDir [C:\Projects\ASF\Configurator\Main\TestResults\rLisdonk_L015 2011-01-19 08_27_21\In\L015]

TestRunDirectory [C:\Projects\ASF\Configurator\Main\TestResults\rLisdonk_L015 2011-01-19 08_27_21]

TestRunResultsDirectory [C:\Projects\ASF\Configurator\Main\TestResults\rLisdonk_L015 2011-01-19 08_27_21\In\L015]

Cleaning a Microsoft Visual Studio solution after setting all files to read-only

Making ".\bin", ".\Release", ".\Debug", ".\obj" not read-only, after accidentally setting the root folder of you’re Microsoft Visual Studio solution to "read-only".

You can use this script:



string sourceFolder = @"C:\Projects"; foreach (string folder in Directory.GetDirectories(sourceFolder, "*", SearchOption.AllDirectories)) { if (folder.EndsWith(@"\obj") || folder.EndsWith(@"\bin") || folder.EndsWith(@"\Release") || folder.EndsWith(@"\Debug"))     {       DirectoryInfo test = new DirectoryInfo(folder);       test.Attributes = FileAttributes.Normal;

       foreach(DirectoryInfo dir in test.GetDirectories("*", SearchOption.AllDirectories))         {

          dir.Attributes = FileAttributes.Normal;


foreach (string file in Directory.GetFiles(folder, "*", SearchOption.AllDirectories))         { File.SetAttributes(file, FileAttributes.Normal); File.Delete(file);          }

} }

How to set the correct border for a datagrid in a datagrid in WPF

If you use a datagrid in the DataGrid.RowDetailsTemplate and set the last column width to * and the datagrid is set to HorizontalAlignment="Stretch", then you might get a horizontal scrollbar. To prevent this, set the HorizontalScrollBarVisibility="Disabled" on the top datagrid and subdatagrids


The first screendump show the datagrids with HorizontalScrollBarVisibility set to “Enabled”, as you can see at the bottom of the screendump, the datagrid contains a horizontal scrollbar. This is, because the last column width is set to *.


The second screendump shows the correct layout (with HorizontalScrollBarVisibility set to "Disabled")