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?
When it doesn’t worksection. 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!