[英]Passing an array argument from Excel VBA to a WCF service
我正在尝试将数组作为参数传递给WCF服务。 为了使用Damian的示例代码进行测试,我修改了GetData,以尝试将一个整数数组而不是单个整数作为参数传递:
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代码:
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)
这段代码可以与WCF测试客户端配合使用,但是当我尝试从Excel中使用它时,我遇到了这个问题。 当Excel到达service1.GetData调用时,它将报告以下错误:
>Run-time error '-2147467261 (80004003)'
>
>Automation error
>Invalid Pointer
接口规范和VBA调用之间似乎有些不兼容。
您是否曾经尝试过将阵列从VBA传递到WCF? 我做错什么了吗,或者使用“服务”绰号不支持此操作?
您可以尝试/检查几件事:
hack的解决方案可能是使用某种分隔符将数组作为单个字符串连接,然后将其传递给数组。 然后在服务中,将字符串拆分回数组。 看来可行,但是我真的想要正确的解决方案。 如果有人可以解决这个问题,请发表!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.