传递从Excel VBA数组参数WCF服务 [英] Passing an array argument from Excel VBA to a WCF service

查看:300
本文介绍了传递从Excel VBA数组参数WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想传递一个数组作为参数传递给我WCF服务。为了测试这个使用达米安的样本code,我修改的GetData它试图通过整数,而不是单个int作为参数数组:

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:

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)

这code正常工作与WCF测试客户端,但是当我尝试从Excel中使用它,我有这个问题。当Excel获取到service1.GetData呼叫时,报告了以下错误:

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

它看起来像有接口规范和VBA调用之间出现不兼容。

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

你有没有试过从VBA传递一个数组到WCF?难道我做错了什么,或者这是不支持使用本服务的绰号?

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?

推荐答案

黑客攻击的解决办法是加入您的阵列使用某种类型的分隔符的一个字符串,并通过数组的替代。然后,在服务上,分割字符串返回数组。它似乎工作,但我真的想正确的解决方案。如果任何人都可以算出来,请张贴!

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!

这篇关于传递从Excel VBA数组参数WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆