Jasper
Jasper

Reputation: 1837

Calling webservice from vbscript > option?

for a project we need to call some webservices from vbscript. This is doable, but it requires building the entire XML fragment by hand. I'm spoiled by .NET so I want to do it better.

There is the option of building a COM component and calling that from vbscript, but unfortunately that also requires registering the COM component on the client, an option we don't have.

Another thing I thought of is building a console application which handles the webservice calls and exceptions and things. Problem here is that I need to return a string to the vbcode, where a consoleapp can only return an exit code and nothing more (as far as I know). Since it's a shared scenario, I can't write to a textfile either since that will cause problems in multiuser scenario's.

So I wondered if there are any options I missed and should consider? Or in the other case: what option would you guys pick and why?

Edit: worth mentioning; the webservice is mine and so is the server on which it runs. It will be secured with SSL and authorization to make sure no one other than our clients can use it. I set it up as a WCF service, but it's to be constructed so I can still change that (either the service type or the bindingtype).

Upvotes: 2

Views: 1889

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039190

The answer would really depend on your exact scenario. For example if you have control over the web service you could expose a netTcpBinding endpoint and then consume it directly from vbscript.

Here's a nice article which shows how to achieve this step by step. Basically your client code might look like that:

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

Dim service1
Set service1 = GetObject(addr)
wscript.echo service1.GetData(123)

The WCF service could either be hosted in WAS in IIS 7.0+ which allows to use netTcpBinding or be self hosted as a Windows Service for example.

Another possibility if you have control over the service is to expose it as a REST which is easier to consume. You could opt for JSON and XML which might still require parsing on the client but at least it will make things cleaner.

And if you are tied to SOAP then the recommended approach is to use the MSXML2.ServerXMLHTTP.6.0 as shown in this answer and build the envelopes manually.

The MSSOAP.soapClient control that shipped with Windows XP is now obsolete even if it allowed to achieve exactly what you were looking for with a SOAP service.

Upvotes: 3

Related Questions