wcf + 响应消息的内容类型 text/html 与绑定的内容类型不匹配(application/soap+xml; charset=utf-8)

kar*_*nam 1 c# wcf binding utf-8 character-encoding

我面临以下错误“响应消息的内容类型 text/html 与绑定的内容类型不匹配 (application/soap+xml; charset=utf-8)。如果使用自定义编码器,请确保IsContentTypeSupported 方法已正确实现。响应的前 514 个字节为"。下面是我的绑定和配置文件

  <customBinding>
                <binding name="LoginServiceSoap12Binding">
                    <textMessageEncoding messageVersion="Soap12" />
                    <httpsTransport />
                </binding>
            </customBinding>

<endpoint address="WCF URL"
             binding="customBinding" bindingConfiguration="LoginServiceSoap12Binding"
             contract="CWALoginService.LoginServicePortType" name="LoginServiceHttpsSoap12Endpoint" />
Run Code Online (Sandbox Code Playgroud)

不确定我在这里面对的是什么问题...

sot*_*otn 5

大多数情况下,这意味着您的主机返回错误页面(因为内容类型text/html如所述)而不是您的服务以application/soap+xml.

您应该通过进入您的服务的 url ( http(s)://localhost{:port}/{subSite}/(WCF URL).svc)来检查您的服务是否可以成功激活。如果您的服务可以被激活,那么您应该尝试的下一件事是通过以下方式在您的客户端和服务端启用 wcf 跟踪:

  • 右键单击您的 web.config/app.config 并单击 Edit WCF Configuration
  • 根据Diagnostics部分,启用Log Auto FlushMessageLoggingTracing,当然指定您的主机的身份访问写的路径。
  • 执行该服务调用后检查跟踪文件。然后你应该看到你的主机返回的 html 并找出真正的问题是什么。