WCF服务 远程服务器返回错误: (415)

曾经终败给现在 2022-04-13 09:22 1009阅读 0赞

在浏览器可以打卡wcf服务接口,但是vs中添加服务引用失败。

  1. 下载“http://192.168.22.148:8080/$metadata”时出错。
  2. 请求失败,HTTP 状态为 404: Not Found
  3. 元数据包含无法解析的引用:“http://192.168.22.148:8080/”。
  4. 服务 http://192.168.22.148:8080/ 不支持内容类型 application/soap+xml; charset=utf-8。
  5. 客户端和服务绑定可能不匹配。
  6. 远程服务器返回错误: (415) Cannot process the message because the content type 'application/soap+xml;
  7. charset=utf-8' was not the expected type 'text/xml; charset=utf-8'.。
  8. 如果该服务已在当前解决方案中定义,请尝试生成该解决方案,然后再次添加服务引用。

解决方法是:
节点中添加:

  1. <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>

配置如下:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <configuration>
  3. <system.serviceModel>
  4. <!--添加到这里-->
  5. <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  6. <services>
  7. <service name="WcfServiceLibrary2.Service1">
  8. <endpoint address="" binding="basicHttpBinding" contract="WcfServiceLibrary2.IService1"></endpoint>
  9. </service>
  10. </services>
  11. <behaviors>
  12. <serviceBehaviors>
  13. <behavior>
  14. <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
  15. <serviceDebug includeExceptionDetailInFaults="False" />
  16. </behavior>
  17. </serviceBehaviors>
  18. </behaviors>
  19. </system.serviceModel>
  20. <system.webServer>
  21. <defaultDocument>
  22. <files>
  23. <add value="WcfServiceLibrary2.Service1.svc" />
  24. </files>
  25. </defaultDocument>
  26. </system.webServer>
  27. </configuration>

  查了好多天,原来就是少了个配置。这是部署在windows Server服务器上,一般的windows客户机系统都不需要,就可以直接访问的到。

发表评论

表情:
评论列表 (有 0 条评论,1009人围观)

还没有评论,来说两句吧...

相关阅读