簡體   English   中英

C#:通過服務引用調用Web服務:缺少內容類型標頭

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM