Call SOAP WebService from Azure Function

Mathes
Member Posts: 21
Dear all,
does someone has experience calling a nav soap webservice from an Azure Function?
Regards
Mathes
does someone has experience calling a nav soap webservice from an Azure Function?
Regards
Mathes
0
Answers
-
Hi Ftornero, thanks, can you share your experience? How can I write an Azure function to call eg. a NAV Page as a SOAP WebServicE?0
-
Hello @Mathes ,
Assuming that you have published the page 21 as a webservice with the name Customer, this Azure function in Powershell call the webserice.# POST method: $req $requestBody = Get-Content $req -Raw | ConvertFrom-Json $customer = $requestBody.customer # GET method: each querystring parameter is its own variable if ($req_query_name) { $name = $req_query_name } function Execute-SOAPRequest ( [String] $SOAPRequest, [String] $URL, [String] $SOAPAction ) { write-host "Enviando petición SOAP al Servidor: $URL" $soapWebRequest = [System.Net.WebRequest]::Create($URL) $username = "user_name" $password = "password" $cred = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force)) $soapWebRequest.Credentials = $cred $soapWebRequest.Headers.Add("SOAPAction", $SOAPAction) $soapWebRequest.ContentType = "text/xml; charset=utf-8" $soapWebRequest.UserAgent = "Microsoft ADO.NET Data Services" $soapWebRequest.Method = "POST" $soapWebRequest.Timeout = 800000 $writer = New-Object System.IO.StreamWriter $soapWebRequest.GetRequestStream(); $writer.WriteLine($SOAPRequest); $writer.Close(); try { $resp = $soapWebRequest.GetResponse() $responseStream = $resp.GetResponseStream() $soapReader = [System.IO.StreamReader]($responseStream) $ReturnXml = [Xml] $soapReader.ReadToEnd() $responseStream.Close() return $ReturnXml } catch { Write-Error $Error[0] } } $url = "http://xx.xx.xx.xx:7047/DynamicsNAV/WS/COMPANYNAME/Page/Customer" $soap = '<?xml version="1.0" encoding="utf-8"?>' + '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ' + 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' + 'xmlns:xsd="http://www.w3.org/2001/XMLSchema">'+ '<soap:Body>' + '<Read xmlns="urn:microsoft-dynamics-schemas/page/customer">' + '<No>' + $customer + '</No>'+ '</Read>' + '</soap:Body>' + '</soap:Envelope>' $action = '"urn:microsoft-dynamics-schemas/page/Customer"' $ret = Execute-SOAPRequest $soap $url $action [xml]$xml = $ret.InnerXML $cust = $xml.Envelope.Body.Read_Result.Customer $hash = @{ status = 200 } $customer_data = @{ no = $cust.No name = $cust.Name address = $cust.Address city = $cust.City county = $cust.County post_code = $cust.Post_Code phone_no = $cust.Phone_No } $hash.add("customer", $customer_data) $json = $hash | ConvertTo-Json Out-File -Encoding default -FilePath $res -inputObject $json
You need to pass a Json like this, in this case 29754 is de customer no.{ "customer": "29754" }
In the Powershell script you need to change with real data this lines$username = "user_name" $password = "password" ..... $url = "http://xx.xx.xx.xx:7047/DynamicsNAV/WS/COMPANYNAME/Page/Customer"
To use Powershell in the Azure function you need to activate this
And then you can create the Powershell function.
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions