visual-studio - 添加服务引用错误405,客户端和服务绑定可能不匹配
问题描述
我创建了一个 WCF 服务,并且在配置文件和代码中都没有更改任何内容。我在同一台 PC 上本地使用“添加服务参考”将其添加为参考,并且它工作正常。但是,当我将它部署到服务器并尝试为其添加服务引用时,会引发错误:
Content Type application/soap+xml; charset=utf-8 was not supported by service https://www.tcs-ksa.net:1204/shm-dev/Service1.svc. The client and service bindings may be mismatched.
The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8
服务配置文件
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5.2"/>
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
</httpModules>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="ApplicationInsightsWebTracking"/>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
preCondition="managedHandler"/>
</modules>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>
客户端配置文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:54794/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>
解决方案
也许您可以尝试将绑定更改为 WebHttpBinding,如下所示:
binding="basicHttpBinding"
并content-type
在您提出请求时添加:
Content-Type: application/xml;charset=utf-8
推荐阅读
- python - 计算两个列表中的词频并将其输出到字典中
- javascript - Javascript中的箭头函数输出
- r - 这个要怎么写才简洁?
- powershell - 从远程网络事件链调用 WebRequest POST InFile
- wordpress - 在 WooCommerce 管理员订单列表中添加带有付款网址的自定义列
- node.js - 无法在 MongoDB 中创建数组 - MERN 堆栈
- next.js - 如何使用 nextjs 在 apollo 服务器中配置 graphql 订阅
- php - 无法弄清楚如何正确地将小数转换为百分比
- html - 'background-image:url(background.svg)' 中的 SVG 不显示
- c# - Crystal Report,水平拟合数据库中的数据