我想使用此WebService:
http://ec.europa.eu/taxation_customs/vies/services/checkvatservice方法:发帖Content-Type应用程序/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请求并在此处获得响应?
预先感谢您。
您也可以使用New-WebServiceProxy
,这在我看来是一个更优雅的解决方案。您不需要构造envelope
您的selve。
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
您应该能够使用Invoke-Webrequest
来处理它。只需将-Method
开关设置为发布并提供您的XML作为身体
使它变得更好:在VIES Check网站上输入自己的增值税编号时,您将收到一个咨询号(用于管理目的)。
您还可以通过调用" 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
其他字段(如TradeNameChatch),您也可以将其用作响应,但据我所知,只有西班牙支持进入验证目的的地址。其他国家没有。