C#:通过服务引用调用 Web 服务:缺少 Content-Type Header
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);
现在抛出以下异常:
'System.ServiceModel.ProtocolException' 类型的异常发生在 mscorlib.dll 但未在用户代码中处理
其他信息:SOAP 消息传递需要 HTTP Content-Type header,并且找到了 none。
编辑:我从 X++ 中调用它 class,如果这有什么不同的话。
也许您需要将设置添加到您的网络配置中。当您添加此 Web 服务时,它必须自动添加。我试过了,它向我返回了数据。
<setting name="WebApplication6_eu_europa_ec_checkVatService" serializeAs="String">
<value>http://ec.europa.eu/taxation_customs/vies/services/checkVatService</value>
</setting>
这可能对你有帮助this
你能试试这个吗?
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 (from which the referenced service was created from), you have to use http://ec.europa.eu/taxation_customs/vies/services/checkVatService
此 link 也自动用于 app.config 文件。 它有效,但由于某种原因它看起来有点不对劲。如果有人能详细解释一下就好了
我正在尝试通过 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);
现在抛出以下异常:
'System.ServiceModel.ProtocolException' 类型的异常发生在 mscorlib.dll 但未在用户代码中处理
其他信息:SOAP 消息传递需要 HTTP Content-Type header,并且找到了 none。
编辑:我从 X++ 中调用它 class,如果这有什么不同的话。
也许您需要将设置添加到您的网络配置中。当您添加此 Web 服务时,它必须自动添加。我试过了,它向我返回了数据。
<setting name="WebApplication6_eu_europa_ec_checkVatService" serializeAs="String">
<value>http://ec.europa.eu/taxation_customs/vies/services/checkVatService</value>
</setting>
这可能对你有帮助this
你能试试这个吗?
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 (from which the referenced service was created from), you have to use http://ec.europa.eu/taxation_customs/vies/services/checkVatService
此 link 也自动用于 app.config 文件。 它有效,但由于某种原因它看起来有点不对劲。如果有人能详细解释一下就好了