C # ASMX Service throwing Тип содержимого text / html;charset = UTF-8 ответного сообщения не соответствует ошибке типа контента - PullRequest
0 голосов
/ 06 мая 2019

Я добавил сервисную ссылку 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);
                }
            }
        }

1 Ответ

0 голосов
/ 07 мая 2019

Добавление этой конфигурации в мой файл 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>
...