1

I'm trying to pass an array as an argument to my WCF service. To test this using Damian's sample code, I modified GetData it to try to pass an array of ints instead of a single int as an argument:

using System;
using System.ServiceModel;

namespace WcfService1
{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(int[] value);
    }
}

using System;
namespace WcfService1
{
    public class Service1 : IService1
    {
        public string GetData(int[] value)
        {
            return string.Format("You entered: {0}", value[0]);
        }
    }
}

Excel VBA code:

Dim addr As String
addr = "service:mexAddress=""net.tcp://localhost:7891/Test/WcfService1/Service1/Mex"","
addr = addr + "address=""net.tcp://localhost:7891/Test/WcfService1/Service1/"","
addr = addr + "contract=""IService1"", contractNamespace=""http://tempuri.org/"","
addr = addr + "binding=""NetTcpBinding_IService1"", bindingNamespace=""http://tempuri.org/"""

Dim service1 As Object
Set service1 = GetObject(addr)

Dim Sectors( 0 to 2 ) as Integer
Sectors(0) = 10
Sectors(1) = 20

MsgBox service1.GetData(Sectors)

This code works fine with the WCF Test Client, but when I try to use it from Excel, I have this problem. When Excel gets to the service1.GetData call, it reports the following error:

>Run-time error '-2147467261 (80004003)'
>
>Automation error
>Invalid Pointer

It looks like there is some incompatibility between the interface specification and the VBA call.

Have you ever tried to pass an array from VBA into WCF? Am I doing something wrong or is this not supported using the Service moniker?

2
  • its interesting to note you can't have the service produce an array in another operationcontract and feed it back as an input from excel directly... gives a type mismatch error Commented Jun 4, 2010 at 1:09
  • Check the blog article again and try to follow the steps he describes at the When it doesn’t work section. He tells how you can attach the Visual Studio debugger to Excel to get more information on the .NET Exception that is being thrown. Maybe if you update your question with this extra information it will be easier to help! Commented Jun 8, 2011 at 14:56

2 Answers 2

0

There are a couple of things that you could try / check:

  1. From your code, it looks like only the first element in your array is set to a value, try setting them all.
  2. Instead of passing an array of int, try passing an object that contains a single property which is an array of int.
Sign up to request clarification or add additional context in comments.

Comments

0

a hack solution could be to join your array as a single string using some kind of delimiter, and pass that instead of the array. Then in the service, split the string back to an array. It seems to work, but I really want the correct solution. If anyone can figure this out, please post!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.