我想使用这个网络服务:
http://ec.europa.eu/taxation_customs/vies/services/checkVatService 方法:POST Content-Type application / xml
这是我的要求:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ec.europa.eu:taxud:vies:services:checkVat:types">
<soapenv:Header/>
<soapenv:Body>
<urn:checkVat>
<urn:countryCode>ES</urn:countryCode>
<urn:vatNumber>A28017895</urn:vatNumber>
</urn:checkVat>
</soapenv:Body>
wsdl在这里:http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl
如何使用powershell发送xml请求并在那里获得响应?
提前谢谢。
答案 0 :(得分:0)
您应该能够使用Invoke-Webrequest
来处理这个问题。只需将-Method
开关设置为POST并将xml作为正文
答案 1 :(得分:0)
您还可以使用New-WebServiceProxy
,在我看来,这是一个更优雅的解决方案。您不需要自己构造envelope
。
Function Get-ViesVatNumber {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true,
Position=0)]
$CountryCode,
[Parameter(Mandatory=$true,
Position=1)]
$VatNumber
)
$Vies = New-WebServiceProxy -Uri "http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl" -Class "checkVat"
$Valid = $false
$Name = ""
$Address = ""
$DateChecked = $Vies.checkVat([ref]$CountryCode, [ref]$VatNumber, [ref]$Valid, [ref]$Name, [ref]$Address)
$Properties = @{
'CountryCode' = $CountryCode
'VatNumber' = $VatNumber
'Valid' = $Valid
'Name' = $Name
'Address' = $Address
'DateChecked' = $DateChecked
}
$Company = New-Object -TypeName PSCustomObject -Property $Properties
Write-Output $Company
}
带有有效增值税的示例
Get-ViesVatNumber -CountryCode "BE" -VatNumber "0420429375"
DateChecked : 02/08/2018 00:00:00
Name : Comm.VA ALPRO
VatNumber : 0420429375
Address : VLAMINGSTRAAT 28
8560 WEVELGEM
Valid : True
CountryCode : BE
示例包含无效的增值税
Get-ViesVatNumber -CountryCode "BE" -VatNumber "0420429335"
DateChecked : 02/08/2018 00:00:00
Name : ---
VatNumber : 0420429335
Address : ---
Valid : False
CountryCode : BE
答案 2 :(得分:0)
为了更好:在VIES支票网站上输入自己的增值税号时,您会收到一个咨询号码(出于管理目的,在您检查时证明该号码有效)。
您还可以通过调用“ checkVatApprox” Web服务而不是“ checkVat”来请求此咨询号码。为此,您需要进行以下修改(很多参数):
$Valid = $false
$Name = ""
$Address = ""
$Identifier = ""
$TraderCompanyType = ""
$TraderStreet = ""
$TraderPostcode = ""
$TraderCity = ""
$TraderNameMatch = 1
$TraderNameMatchSpecified = $false
$TraderCompanyTypeMatch = 1
$TraderCompanyTypeMatchSpecified = $false
$TraderStreetMatch =1
$TraderStreetMatchSpecified = $false
$TraderPostcodeMatch = 1
$TraderPostcodeMatchSpecified = $false
$TraderCityMatch = 1
$TraderCityMatchSpecified = $false
$RequesterCountryCode = "YourCountryCode"
$RequesterVatNumber = "YourVATNumber"
$DateChecked = $Vies.checkVatApprox([ref]$CountryCode, [ref]$VatNumber, [ref]$Name, [ref]$TraderCompanyType, [ref]$TraderStreet, [ref]$TraderPostcode, [ref]$TraderCity, $RequesterCountryCode, $RequesterVatNumber, [ref]$Valid, [ref]$Address, [ref]$TraderNameMatch, [ref]$TraderNameMatchSpecified, [ref]$TraderCompanyTypeMatch, [ref]$TraderCompanyTypeMatchSpecified, [ref]$TraderStreetMatch, [ref]$TraderStreetMatchSpecified, [ref]$TraderPostcodeMatch, [ref]$TraderPostcodeMatchSpecified, [ref]$TraderCityMatch, [ref]$TraderCityMatchSpecified, [ref]$Identifier)
请注意,$ RequesterCountryCode和$ RequesterVatNumber不需要[ref]。这使我在注意到之前已经对此请求寻找了年龄。
现在一切正常,如果添加以下内容:
$Properties = @{
'CountryCode' = $CountryCode
'VatNumber' = $VatNumber
'Valid' = $Valid
'Name' = $Name
'Address' = $Address
'DateChecked' = $DateChecked
'Consultation' = $Identifier
}
您将收到以下答复:
Get-ViesVatNumber -CountryCode "BE" -VatNumber "0420429375"
DateChecked : 8/13/2019 10:00:00 PM
Name : Comm.VA ALPRO
VatNumber : 0420429375
Address : VLAMINGSTRAAT 28
8560 WEVELGEM
Valid : True
CountryCode : BE
Consultation: WAPIAAAAWyQb9ELI
其他字段,例如TraderNameMatch,也可以将它们用作响应,但是据我所知,只有西班牙支持输入地址以进行验证。其他国家没有。