问题描述
我在尝试将 WCF 服务添加到 WCFTestClient 时收到以下错误.我在网上经历了许多解决方案,但我无法让它工作.
I am getting the error below while trying to add WCF service to WCFTestClient. I went through a number of solutions on the web but I couldn't get it to work.
有人可以帮我解决问题吗?我还提供了我的服务配置文件:
Can someone help me with the issues?I am also providing my config file for service:
内容类型应用程序/soap+xml;charset=utf-8 不受支持service 客户端和服务绑定可能不匹配.这远程服务器返回错误:(415) 无法处理消息因为内容类型'application/soap+xml;charset=utf-8' 不是预期的类型 'text/xml;字符集=utf-8
代码:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file
must be added to the host's app.config file. System.Configuration does not
support config files for libraries. -->
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttp" allowCookies="true"
maxReceivedMessageSize="20000000"
maxBufferSize="20000000"
maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32"
maxArrayLength="200000000"
maxStringContentLength="200000000"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="WCFTradeLibrary.TradeService">
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="basicHttp"
contract="WCFTradeLibrary.ITradeService">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint
above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faul`enter code here`ts for
debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception info`enter code here`rmation -->
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
推荐答案
我遇到了命名问题.服务名称必须与您的实现完全相同.如果不匹配,它默认使用 basicHttpBinding
导致 text/xml
内容类型.
I run into naming problem. Service name has to be exactly name of your implementation. If mismatched, it uses by default basicHttpBinding
resulting in text/xml
content type.
您的班级名称在两个位置 - SVC 标记和 CS 文件.
Name of your class is on two places - SVC markup and CS file.
也检查端点合同 - 再次是您接口的确切名称,仅此而已.我添加了无法存在的程序集名称.
Check endpoint contract too - again exact name of your interface, nothing more. I've added assembly name which just can't be there.
<service name="MyNamespace.MyService">
<endpoint address="" binding="wsHttpBinding" contract="MyNamespace.IMyService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
这篇关于内容类型应用程序/soap+xml;服务不支持 charset=utf-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!