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

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

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

解决方法是:
在<system.serviceModel>节点中添加:

 <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>

配置如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
  
    <!--添加到这里-->
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    
    <services>
      <service name="WcfServiceLibrary2.Service1">
        <endpoint address="" binding="basicHttpBinding" contract="WcfServiceLibrary2.IService1"></endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
    <system.webServer>
        <defaultDocument>
            <files>
                <add value="WcfServiceLibrary2.Service1.svc" />
            </files>
        </defaultDocument>
    </system.webServer>
</configuration>

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

评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值