It looks like you're new here. Sign in or register to get started.
# 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
{ "customer": "29754" }
$username = "user_name" $password = "password" ..... $url = "http://xx.xx.xx.xx:7047/DynamicsNAV/WS/COMPANYNAME/Page/Customer"
Answers
Yes I have some experience calling a NAV webservice from an Azure Function.
Regards.
Assuming that you have published the page 21 as a webservice with the name Customer, this Azure function in Powershell call the webserice.
You need to pass a Json like this, in this case 29754 is de customer no.
In the Powershell script you need to change with real data this lines
To use Powershell in the Azure function you need to activate this
And then you can create the Powershell function.