Search code examples
c#visual-studio-2010wcfwcftestclient

Entering values for a Byte array in WCF Test client


I'm trying to use the WCF test client to debug a web method and the method expects 2 byte arrays as part of its input.

For now, I've just been using the debugger and placing breakpoints right before the passed values get used, and setting them with the visual studio watch window.

Is there an easy way to set the values for each byte of a byte array using WCF test client?

I know you can specify the length of the array by typing "length=100" or similar, but that only sets the size of the array. You then have to click the drop down and enter the value for each and every byte one by one.

Does anyone have experience entering values for arrays when using the WCF test client?


Solution

  • What I've done is creating a static method that accepts the array and the new value (I sometimes pass a comma-separated string and split it, sometimes I pass a "params" arg, etc.).

    With this, you can call the method on the debugger watch or immediate window. For example, you can call "SetArrayOne()" anytime you need to preset the values, or you can call "SetArray(...)" and pass your desired arguments:

    byte[] myClassLevelArray1 = new byte[10];
    byte[] myClassLevelArray2 = new byte[10];
    
    public void SetArrayOne()
    {
        SetArray(myClassLevelArray1, 1, 2, 3, 4, 5);
    }
    
    public void SetArrayTwo()
    {
        SetArray(myClassLevelArray2, 1, 2, 3, 4, 5, 8, 9, 10, 11, 15, 20, 5, 98, 5, 4);
    }
    
    public static void SetArray(byte[] myArray, params byte[] newValues)
    {
        Array.Copy(newValues, myArray, Math.Min(newValues.Length, myArray.Length));
    }