簡體   English   中英

C#ASMX服務拋出內容類型text / html; charset =響應消息的UTF-8與內容類型錯誤不匹配

[英]C# ASMX Service throwing The content type text/html; charset=UTF-8 of the response message does not match the content type error

我通過右鍵單擊根目錄 - >添加服務引用,為我的項目添加了ASMX服務引用。

我的web.config文件中有這樣的:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="xxx" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="serviceaddress"
        binding="basicHttpBinding" bindingConfiguration="xxx"
        contract="xxx" name="xxx" />
    </client>
  </system.serviceModel>

此服務有一個方法,該方法接收帶有用戶名的string並驗證其是否存在。

問題是我在Postman上測試它並且它返回以下錯誤消息:

The content type text/html; charset=UTF-8 of the response message does not match the content type

我已經檢查了類似這樣的其他帖子,但我無法找到解決方案。

這是我調用的拋出錯誤的方法:

public static List<UserInformation> GetUsersByUserName(string userName)
        {
            try
            {
                var usersServiceClient = new LDapServicesSoapClient();
                var requestMessage = new LDapUserNameLookupRequest();
                requestMessage.UserName = userName;
                requestMessage.AccessKey = "secretkey";
                var response = usersServiceClient.LDapGetUserByUserName(requestMessage);
                return response.Users.ToList();
            }
            catch (CommunicationException e)
            {
                if (e.InnerException is QuotaExceededException)
                {
                    throw new Exception("We have found many users, please write another filter");
                }
                else
                {
                    throw new Exception(e.Message, e);
                }
            }
        }

將此配置添加到我的web.config文件中可以實現:

 <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="LDapServicesSoap" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
          <security mode="Transport">
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
            <message clientCredentialType="Certificate" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="address"
        binding="basicHttpBinding" bindingConfiguration="LDapServicesSoap"
        contract="LDapServices.LDapServicesSoap" name="LDapServicesSoap" />
    </client>
  </system.serviceModel>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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