c# - C# ASMX Service throwing 内容类型 text/html; charset=UTF-8 的响应信息与内容类型不匹配错误
问题描述
我 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
带有用户名的 a 并验证它是否存在。
问题是我正在对其进行测试,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>
推荐阅读
- reactjs - 带有作为参数传递的属性的 Wordpress Gutenberg SetAttributes
- python-3.x - 我在代码的最后一行收到一条错误消息
- mailchimp - SPF 失败我不理解 mailchimp
- c# - 当我将测试发送到另一个应用程序时,我无法输入进入应用程序
- user-interface - 编写确认(是/否)对话框
- xamarin - 页面关闭时 Xamarin 形成 Xfx.Controls 异常
- android - 出现软键盘时如何隐藏底部导航菜单?
- java - 如何为枚举对象编写自定义提供程序?
- reactjs - React + Laravel - 显示 HTML 的 Response.data
- swift - 什么可能导致 SwiftUI 和 NavigationView 出现此动画错误?