如何在C#中使用VIES SOAP服务检查欧盟增值税 [英] How to check EU VAT using VIES SOAP service in C#
问题描述
我有一个ASP.NET网站,需要检查用户提供的增值税. VIES服务可以用于暴露
I have an ASP.NET website that needs to check a user-supplied VAT. The VIES Service can be used for that which exposes a SOAP API.
我需要一个简单的示例,说明如何使用此服务验证增值税.在PHP中,这是以下4行: https://stackoverflow.com/a/14340495 .对于C#,我发现2010年有些文章不起作用,或者是数十行甚至数百行的包装器",帮助器服务"等.
I need a dead-simple example on how to validate a VAT using this service. In PHP, it's these 4 lines: https://stackoverflow.com/a/14340495. For C#, I have found some articles from 2010 that do not work or are tens or even hundreds lines of "wrappers", "helper services" etc.
我不需要任何东西,有人可以提供类似PHP的四层衬套来检查C#中的增值税吗?谢谢.
I don't need any of that, can someone provide PHP-like four-liner that would check VAT in C#? Thank you.
推荐答案
我发现的最简单的方法就是发送XML并在返回时对其进行解析:
The simplest way I found is just to send an XML and parse it when it comes back:
var wc = new WebClient();
var request = @"<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>COUNTRY</urn:countryCode>
<urn:vatNumber>VATNUMBER</urn:vatNumber>
</urn:checkVat>
</soapenv:Body>
</soapenv:Envelope>";
request = request.Replace("COUNTRY", countryCode);
request = request.Replace("VATNUMBER", theRest);
String response;
try
{
response = wc.UploadString("http://ec.europa.eu/taxation_customs/vies/services/checkVatService", request);
}
catch
{
// service throws WebException e.g. when non-EU VAT is supplied
}
var isValid = response.Contains("<valid>true</valid>");
这篇关于如何在C#中使用VIES SOAP服务检查欧盟增值税的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!