COM (Vb/VBA/script)Call with service tagWCFService
Usage 3WSDLContract
Lazybee(Http://lazybee.cnblogs.com)
We have introduced how to use MEX The service of the contract is marked in Com Calling WCF Service. MEX The endpoint dynamically acquires metadata, which is convenient to use. However, sometimes the metadata of the service may contain information about the application that malicious users can use.ProgramThat is to say, some services may not pass MEX Publish metadata information. If some services do not publish metadata information, it is difficult to use data types. Com Calling WCF What about services? In this case, we can use WSDL Contract to carry out WCF This method is used to call a service. MEX Similarly, you do not need to register the type, and the information is obtained dynamically. However, a bad thing is that you need to use other methods to obtain the service. WSDL Description. Okay. Let's get started.
Step 1: CreateWCFService
This is exactly the same as the previous article. For more information, see COM (Vb/VBA/script)Call with service tagWCFOne service uses a typed contract The first stepArticleAfter testing, you can directly use the created service.
Step 2:ScriptCallingWCFService
1:ScriptFile, we name itCallwcfservice_wsdl.vbs,The content is as follows:
1 ' ---------------------------------------------------------------
2 ' WSDL service moniker example
3 ' ---------------------------------------------------------------
4
5 Set XMLHTTP = Createobject ( " Msxml2.xmlhttp " )
6 Call XMLHTTP. Open ( " Get " , " Http: // localhost/wcfservicemoniker/service1.svc? WSDL " , False )
7 XMLHTTP. Send
8 ' Msgbox message will be truncated, but wscript. Echo will not.
9 ' Wscript. Echo XMLHTTP. responsetext
10 Wsdlstr = XMLHTTP. responsetext
11
12 Mexico monikerstring = " Service: Address = 'HTTP: // localhost/wcfservicemoniker/service1.svc' "
13 Mexico monikerstring = Mexico monikerstring + " , WSDL =' " & Wsdlstr & " ' "
14 Mexico monikerstring = Mexico monikerstring + " , Binding = wshttpbinding_iservice1, bindingnamespace = 'HTTP: // tempuri.org /' "
15 Mexico monikerstring = Mexico monikerstring + " , Contract = iservice1, contractnamespace = 'HTTP: // tempuri.org /' "
16
17 ' Create the service moniker object
18 Set Mexservicemoniker = GetObject (Mexmonikerstring)
19
20 ' Call the service operations using the moniker object
21 Wscript. Echo mexservicemoniker. sayhello ( " I am lazybee, my blog is http://lazybee.cnblogs.com/ " )
22
23 Set Mexservicemoniker = Nothing
24 Set XMLHTTP = Nothing
25
Note: The service tag string contains the service address, WSDL , Binding and namespace, service contract, and namespace. For more information about how to obtain service addresses, bindings and namespaces, service contracts, and namespaces, see the previous article. COM (Vb/VBA/script) call with service tags WCF service 2 usage Mex contract Step 2
4After saving it, double-click it to run it. Then you can see the running result:
the Source Code in this article is: http://files.cnblogs.com/LazyBee/CallWCFService_wsdl.zip
(For reprint, please indicate the source:Http://lazybee.cnblogs.com)