From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

SOAP web service possible to access from LabView?

Solved!
Go to solution

I like to connect to a webservice of the SOAP type from my Labview code (PC), or at least understand if it possible and how hard it will be.

Just googling "Labview SOAP" gives some hits, so it looks like people are doing this, but I have found any how to, white paper or examples yet.

 

Can anybody ligh up my darkness about SOAP web services and Labview?

 

I also understand that web services is often described in wsdl-files (web service description language). A wsdl file completely describes a web services functionality, and in some languages you can import such a file and say "give me the code skeletton for accessing this web service". Can something like this be done in Labview?

 

Ola (Just installed LV2015)

0 Kudos
Message 1 of 13
(13,078 Views)

Hi,

 

you can access SOAP  webservices, by simply opening the right link via HTTP. This works just fine, all it takes is a bit of string concatenation and then to send it using the HTTP Post VI



Remember Cunningham's Law
Message 2 of 13
(13,047 Views)

Hello,

 

you can find some examples at the end of this topic: https://lavag.org/topic/9826-soap-server-is-it-possible/

 

Best regards.

 

0 Kudos
Message 3 of 13
(13,031 Views)

Hm, I feel I have all tools to test accessing web services with POST.vi. But I don't know exactly how to form the url and buffer parts to make upp a valid html/SOAP request. I have examples from the SoapUI test system, but they produce server side errors so they are definately not correct.

 

First a few words about my setup, can be useful for others also

1. I started with the book "Web Service Testing with soapUI"

2. In chapter two they descibe how to deploy an example web service, Hotel reservation. I did this in linux. (Only had to use a mysql/JDBC driver older that then latest)

3. The web service is running, I can see it in a web browser as http://10.114.100.99:8080/axis2/services/ and also view the wsdl files.

4. I can test it with soapUI, from the wsdl soapUI produces test requests that work when run inside the soapUI. I can add guests, view guests etc.

 

What I tested

I just stared with an POST.vi and changed the url and buffer inputs to different things I thought to be a correct soap request.

1. With url="http://www.ni.nom" and empty body I get the html response of NI home page. Ok.

2, From the test cases in soapUI i copied the following url, empty body

  http://10.114.100.99:8080/axis2/services/GuestManagementService.GuestManagementServiceHttpSoap11End

  Gives response "HTTP/1.1 500 The service cannot be found for the endpoint reference (EPR) /axis2/services/GuestManagementService.GuestManagementServiceHttpSoap11End..."

3. I used same url as in (2) and tried to copy both the xml and raw format of the requests from soapUI (see below) with

same error.

4. As i suspected the raw format from soapUI is not complete (no <soap env...> I tried to combine the raw and xml formats, also added a <?xml version='1.0'...> tag. Same error,

5. If I change the url to http://10.114.100.99:8080/axis2/services/GuestManagementService I get

HTTP/1.1 500 Internal server error. <faultstring>String index out of range: -1</faultstring>. No error on the web service server.

6. If I change the url to http://10.114.100.99:8080/axis2/services/ i get

HTTP/1.1 500 The service cannot be found for the endpoint reference (EPR) /axis2/services/

 

So I feel I am close to reapiting in labiview the soapUI test cases, but what do I do wrong?

 

 

Code for request getGuestDetails in soapUI

 

### raw format chosen in soapUI request editor ###

### looks like the soap message is lacking ###

 

POST http://10.114.100.99:8080/axis2/services/GuestManagementService.GuestManagementServiceHttpSoap11Endp... HTTP/1.1

Accept-Encoding: gzip,deflate

Content-Type: text/xml;charset=UTF-8

SOAPAction: "urn:getGuestDetails"

Content-Length: 336

Host: localhost:8080

Connection: Keep-Alive

User-Agent: Apache-HttpClient/4.1.1 (java 1.5)


### just a row I saw in SOAP resonses ###
<?xml version='1.0' encoding='UTF-8'?>

 

### xml format chosen in soapUI request editor ###
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://sample.com/reservation/guest/types">
   <soapenv:Header/>
   <soapenv:Body>
      <typ:getGuestDetails>
         <!--Optional:-->
         <typ:guestName>Ola2</typ:guestName>
      </typ:getGuestDetails>
   </soapenv:Body>
</soapenv:Envelope>

 

 

 

 

 

 

0 Kudos
Message 4 of 13
(13,017 Views)

Ok, so if you're making a HTTP request you have the following parts:

1) The URL you're connecting to on the remote server - you should know what this is

2) The HTTP headers

3) The 'content'

 

The HTTP Client VIs put these parts together into a HTTP Request (sending a string on a TCP port and reading the response) for you.

 

The content is just the string 'buffer' - from the looks of what you've said this needs to be appropriately formatted XML.

 

The headers is the slightly trickier part but you can use the HTTP Client functions to set additional key/value pairs in the header e.g. SOAPAction

 

If you can make a valid request from another program/tool, you should be able to replicate that using LabVIEW - if you can post the full request/response string for a valid request then we can try and help you out further.


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 5 of 13
(13,002 Views)
Solution
Accepted by topic author Ola_A

Thanks Sam!

That was the last piece I needed! Now it works!

I took the url, headers, and body from the SoapUI test case as in my earlier post. See pictures and attachment.

 

What this vi does:

It invokes the web service GuestManagementService at my local server (see url)

It performs the SOAP action getGuestDetails (see header)

The guestName is Ola4 (see body)

 

In the body of the result you can find (with difficulty)

adress= The nest, Norrland

age=467

name=Ola4

 

Quite cool! But a lot of work for a simple database lookup.

Thanks all for the help.

 

My next step is to understand what labview tools exist to help me create and handle xml-files, but that is for next week.

Message 6 of 13
(12,983 Views)
Solution
Accepted by topic author Ola_A

I only skimmed through the thread, and I understand you already have a solution, but you can also look at an automated tool LV has for accessing web services (should be under Tools>>Import).

 

I haven't used it myself, but my understanding is that this wizard looks at the WSDL published by the web service and uses it to generate VIs for calling all the functions which it exposes, similar to how the shared library import wizard works. This only works for SOAP, but that's OK, because that's what you have.


___________________
Try to take over the world!
Message 7 of 13
(12,974 Views)

Cool! Glad you figured it out!


My next step is to understand what labview tools exist to help me create and handle xml-files, but that is for next week.


Here are some pointers for a head-start next week:

- You can just use string functions and do it that way for simple xml generation/parsing

- LabVIEW can convert any data-type to XML, but in it's own (rather clunky!) schema.

- There are 3rd party toolkits on the LabVIEW tools network for handling XML

- .NET has a pretty comprehensive XML library


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 8 of 13
(12,963 Views)

Thanks tst for showing the code generator for web services! That was really cool!

I could repeat what I did manually in just a few minutes, wow!

0 Kudos
Message 9 of 13
(12,953 Views)

Dear All,

 

Could anybodey help me to resolve problem about reading data.  

 

Attached please find pictures from SoapUI and LabVIEW.

 

Thank you for support.

0 Kudos
Message 10 of 13
(11,504 Views)