COM (Vb/vba/script) invokes WCF service with service tag use MEX contract

Source: Internet
Author: User
Tags wsdl

First step: Create a WCF Service

We used the service tag of the typed contract to invoke the WCF service in COM, but this has some limitations because the. NET Framework is required because of the need to register the type, but in many cases the COM client's environment does not have the. NET Framework, For example, in Excel, you need to call a WCF service to compute the value of a cell, and the Excel file may be distributed to many machines, and you can't always install a. Net Framework for each machine, and you'll have to register the type you need. For this scenario, we can use the service tag of the MEX contract to get the service contract dynamically, so that we can meet the requirements of the above scenario. Let's get started here!

This is exactly the same as the previous one, please see COM (vb/vba/script) using service tokens to invoke one of the WCF services using a typed contract, if you've ever done the appropriate testing on the previous article, you can use the services you've built directly. Step two: Invoke WCF services in script 1 here you can see from the previous one that there are no steps to create the client library and register, but to invoke the WCF service directly. Before writing the calling code, let's start by opening the WSDL for the service, because there are the service tag information we need. 2 We open http://localhost/WCFServiceMoniker/Service1.svc? After the WSDL, the following figure shows:

3 The following is the creation of our script file, we named Callwcfservice_mex.vbs, the contents are as follows:

 1 '---------------------------------------------------------------2 ' MEX service moniker Example 3 '---------------------------------------------------------------4 ' Create a string for the service moniker specifying The address 5 ' to retrieve the service metadata from 6mexMonikerString = ' service:mexaddress= ' Http://localhost/WCFServic Emoniker/service1.svc/mex ' "7mexMonikerString = mexmonikerstring +", address= ' http://localhost/WCFServiceMoniker/ Service1.svc ' "8mexMonikerString = mexmonikerstring +", Binding=wshttpbinding_iservice1, bindingnamespace= ' http://
tempuri.org/' "9mexMonikerString = mexmonikerstring +", Contract=iservice1, contractnamespace= ' http://tempuri.org/' Create the service moniker object 11Set Mexservicemoniker = GetObject (mexmonikerstring) ' Call the service operation s using the moniker Object 13wscript.echo Mexservicemoniker.sayhello ("I am Lazybee, my blog is http://lazybee.cnblogs.co m/") 14Set Mexservicemoniker = Nothing 

Mex Address, service address, binding and namespace, service contract, and namespace four parts. Here the service address is the address shown above, of course Mex address is to add a mex behind it, this should be very good for everyone to understand. Bindings and services are also highlighted in the figure above, but note that the case is case-sensitive because it is case sensitive in service tags, because we do not specify namespaces for service contracts and bindings, the default is "http://tempuri.org/".

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.