Excel VBA calls WebService in two ways to solve mssoap30 64-bit incompatibility Problem

Source: Internet
Author: User

Although it is a very old technology, but when it comes to it, let's talk about it .....

Office EXCEL uses VBA to call WebService in two ways:

1. N years ago, Microsoft provided the mssoap30 component and compiled it for VC ++.. Net calls WebService in a similar way. They all add references, but the fatal defect is that 64-bit office is not supported.Program(Supports 32-bit office running on 64-bit machines), and Microsoft has explicitly reminded developers that it has abandoned mssoap30 and replaced it with office development of the framework.

This cannot be achieved ....

2. the basic HTTP method is used. This method is very good. Theoretically, any URL can be called to accept responsebody. It perfectly supports the WSDL and restful WebService. the Ajax call method must be enabled for the WSDL WebService developed by. net.

 Function Getwsrrrlt (xmlstr As   String ) As   String  Dim  Objhttp, xmldoc  ' Call WebService Method  Set Objhttp = Createobject ( "  Msxml2.xmlhttp  "  )  Set Xmldoc = Createobject ( "  MSXML. domdocument  "  ) Strwebserviceurl = " Http: // 192.168.0.114/wsrr. asmx/callbyxml  "  Objhttp. Open  "  Post  " , Strwebserviceurl, False'Post method is used by default.  Objhttp. setRequestHeader  "  Content-Type  " , "  Application/JSON  "  Objhttp. Send ( "  {Xmlinput :'  " & Xmlstr & "  '}  "  )'Xmlinput is a ws parameter.Getwsrrrlt = CSTR (Bytestobstr (objhttp. responsebody ), "  UTF-8  "  ) Getwsrrrlt =Getstringbyjson (getwsrrrlt)'. Net3.5 ,. for net4.0 and later WS, The JSON character format returned by default is {"D": "Here is the expected JSON, for example {" result ":" 1 "}"}  '  Parse JSON format  '  Dim objsc, strjson, objjs  '  Strjosn = "{" "myname" ":" "liucqa" "," "myid" ":" 007 ""}"  '  Set objsc = Createobject ("msscriptcontrol. scriptcontrol") 'calls the scriptcontrol object  '  Strjson = "Var o =" & strjosn &";"  ' Objsc. Language = "JavaScript"  '  Objsc. addcode (strjson)  '  Set objjs = objsc. codeobject. o  '  Msgbox callbyname (objjs, "myname", vbget) & "=" & callbyname (objjs, "myid", vbget)  '  Dim soapclient as soapclient30  '  Set soapclient = Createobject ("mssoap. soapclient30 ")  ' Soapclient. mssoapinit "http: // 192.168.0.114/wsrr. asmx? WSDL "," wsrr "," wsrrsoap ",""  '  Soapclient. clientproperty ("serverhttprequest") = true  '  Getwsrrrlt = CSTR (soapclient. callbyxml (xmlstr ))  End Function 

 

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.