Click here to Skip to main content
13,793,623 members
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

10.7K views
3 bookmarked
Posted 9 Dec 2016
Licenced CPOL

Consume SOAP Service with COM Component

, 12 Dec 2016
Rate this:
Please Sign up or sign in to vote.
This article explains how to consume a WebService (SOAP) from plain VisualBasicScript by using a COM DLL written in C#.

Sure there is a way to send a request to SOAP service "manually" by writing down a XML file and posting it to server as HTTP POST like this.

This is however a hard way, you need to handle such a complex structures like:

<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:soap=""http://www.w3.org/2003/05/soap-envelope"" 

xmlns:fruit=""http://fabrikam.net""><soap:Header/><soap:Body>
<fruit:findBananasbyId><Id>" & bananaId & /Id></fruit:findBananasById></soap:Body></soap:Envelope>"

and believe me, that is just a beginning. :)

On the other side, it is very simple to create a client application to consume a SOAP service in Visual Studio. Take a look for example at this link.

Now you can create a .NET library (DLL) but how to use it from a VBS?

The answer is - the DLL need to be a COM object!

Assumed we have such a COM-DLL, we can easily use it:

Dim oComSoap
Set oComSoap = CreateObject("myComInterface")
oComSoap.SendRequest

There are certainly two points / pitfalls:

  1. The .NET WCF Application has an app.config looking like this:
    < system.serviceModel >
            < bindings >
              < wsHttpBinding >
                   < binding name = "WSHttpBinding_PurchaseInvoiceService" />
              </ wsHttpBinding >
            </ bindings >
            < client >
              < endpoint address = 
              "http://ax5-w8r2-01.contoso.com/MicrosoftDynamicsAXAif50/purchaseinvoiceservice.svc"
    
                      binding = "wsHttpBinding" 
    
                      bindingConfiguration = "WSHttpBinding_PurchaseInvoiceService"
    
                      contract = "PurchaseInvoiceService.PurchaseInvoiceService" 
    
                      name = "WSHttpBinding_PurchaseInvoiceService" >
                  < identity >  
                    < userPrincipalName value = "Administrator@contoso.com" />
                  </ identity >
              </ endpoint >
            </ client >
    </ system.serviceModel >

    Your stand-alone DLL makes no use of app.config and shall replace it by creating an according class:

    PurchaseInvoiceServiceClient _oClient;
    
    WSHttpBinding oBinding = new WSHttpBinding();
    oBinding.Name = "WSHttpBinding_PurchaseInvoiceService";     
    string strEndPoint = 
    "http://ax5-w8r2-01.contoso.com/MicrosoftDynamicsAXAif50/purchaseinvoiceservice.svc";
    EndpointAddress oEndPoint = new EndpointAddress(strEndPoint);
    _oClient = new PurchaseInvoiceServiceClient(oBinding, oEndPoint);
  2. The .NET WCF Application marks an entry point / the main function as [STAThread] that means, the COM threading model for an application is single-threaded apartment (STA).

    This is what you need to do for every SOAP interface of your DLL:

    [STAThread]
    public bool SendRequest()

Points of Interest

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

_duDE
Software Developer
Germany Germany

You may also be interested in...

Pro

Comments and Discussions

 
QuestionInsane Pin
EMiller829-Dec-16 7:45
memberEMiller829-Dec-16 7:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.181207.3 | Last Updated 12 Dec 2016
Article Copyright 2016 by _duDE
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid