Hashtable to VBA using SOAP Toolkit

S

Salman

How an ASP.Net webservice return hashtable or any other (key value pairs
like structure) that can be consumed in VBA or vbscript like this following
(using Soap Toolkit):

value1 = soapProxy.Items["Key1"]
value2 = soapProxy.Items["Key2"]

Thanks.
 
M

[MSFT]

Hi Salman,

The hashtable or collection objects used in asp.net service are classes in
..NET framework, which cannot be refered in VBA or VBScript directly, I
suggest you may use array instead, for example, such a web method:


[WebMethod]
public string [] GetStringArray()
{
string [] results= new string[3] ;

results[0]="sss";
results[1]="sss";
results[2]="sss";

return results;
}


On client side, we can use following code:


Dim rs

strWSURL = "..."
SoapClient.MSSoapInit(strWSURL)

rs = SoapClient.GetStringArray()
MsgBox rs(0)

Hope this help,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Salman

Thanks for your response.
Let me rephrase my question.

What datatype should I use in a .Net webservice that can be loaded in vba
like a key-value pair collection.
value1 = soapProxy.Items["Key1"]
value2 = soapProxy.Items["Key2"]
 
M

[MSFT]

Hi Salman,

I have to tell the answer is "No such one" to the question. All collections
used in VBA/VBScript are COM based, which cannot be passed from a .NET web
service.

If you need a collection from a web service, you may first get the XML data
of the XML service and then convert it to a collection object. For example,
here is a web method:

public struct MyItem
{
public string key;

public string myvalue;

}

[WebMethod]
public MyItem [] Getitems()
{
MyItem [] ddd= new MyItem[2] ;

ddd[0].key ="key1";

ddd[0].myvalue="hello ";

ddd[1].key ="key2";

ddd[1].myvalue="World";

return ddd;
}


It will return an array of MyItem objects. On client side:

soapProxy.ClientProperty("ServerHTTPRequest") = True
soapProxy.MSSoapInit ("http://localhost/WebService6/Service3.asmx?wsdl")

Dim results

results = soapProxy.GetItems()


Dim mydictionary

Set mydictionary = CreateObject("scripting.dictionary")

Dim i

For i = 0 To UBound(results)

mydictionary.Add results(i)(0).Text, results(i)(1).Text

Next

MsgBox mydictionary("key1") + mydictionary("key2")

Hope this help,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top