[英]C#: Calling web service through service reference: Content-Type Header missing
我正在尝试通过C#访问http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl 。
我已将其添加为服务参考。 现在我有以下代码:
public static string checkVat(string _countryCode, string _vatNumber, string _companyName, bool _isValid, string _companyAdress)
{
var binding = new BasicHttpBinding();
var endpointAddress = new EndpointAddress("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl");
var client = new ServiceReferenceCheckVat.checkVatPortTypeClient(binding, endpointAddress);
string response = client.checkVat(ref _countryCode, ref _vatNumber, out _isValid, out _companyName, out _companyAdress);
return response;
}
这行:
string response = client.checkVat(ref _countryCode, ref _vatNumber, out _isValid, out _companyName, out _companyAdress);
现在抛出以下异常 :
mscorlib.dll中发生类型'System.ServiceModel.ProtocolException'的异常,但未在用户代码中处理
附加信息:SOAP消息传递需要HTTP Content-Type标头,但没有找到。
编辑:如果有什么区别,我从X ++调用此类。
也许您需要将设置添加到您的Web配置中。 添加此Web服务时,必须自动添加它。 我尝试过,它重新为我调整了数据。
<setting name="WebApplication6_eu_europa_ec_checkVatService" serializeAs="String">
<value>http://ec.europa.eu/taxation_customs/vies/services/checkVatService</value>
</setting>
这可能会帮助你这个
你可以试试这个吗?
public static string checkVat(string _countryCode, string _vatNumber, string _companyName, bool _isValid, string _companyAdress)
{
var client = new eu.europa.ec.checkVatService();
return client.checkVat(ref _countryCode, ref _vatNumber, out _isValid, out _companyName, out _companyAdress).ToString();
}
得到它的工作。 问题是端点地址错误。
不必使用http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl (从中创建引用服务的位置),而必须使用http://ec.europa.eu/taxation_customs/vies/services / checkVatService
这个链接也会在app.config文件中自动使用。 它可以工作,但是由于某种原因,看起来有点不对劲。 如果有人可以解释得更多,那就太好了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.