首页 > 解决方案 > 从浏览器调用 JSON Rest 服务

问题描述

想在我的 REST JSON WCF 服务上启用 https 并在 IE 浏览器中对其进行测试。WSDL 加载没有问题(https://localhost/myservice/Imyservice.svc?WSDL)。但我试图调用一个操作(https://localhost/myservice/Imyservice.svc/Getdata),我收到 请求错误服务器在处理请求时遇到错误。. 下面是我的 web.config。谁能帮我这个

  <webHttpBinding>
    <binding name="SecureBasicRest" allowCookies="true" >
      <security mode="Transport" />
      <readerQuotas maxDepth="32"/>
    </binding>
  </webHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="svcBehavior">
      <serviceMetadata httpsGetEnabled="true" httpGetEnabled="false"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="svcEndpoint">
      <webHttp helpEnabled="true"/>
    </behavior>
  </endpointBehaviors>

</behaviors>
<services>
  <service name="myservice.Imyservice" behaviorConfiguration="svcBehavior">
    <endpoint binding="webHttpBinding" bindingConfiguration="SecureBasicRest"
              behaviorConfiguration="svcEndpoint" name="webHttp"
              contract="myservice.Imyservice" />
  </service>

</services>


<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

标签: restwcfhttps

解决方案


根本原因是服务端点的定义有问题。

<service name="myservice.Imyservice" behaviorConfiguration="svcBehavior">
    <endpoint binding="webHttpBinding" bindingConfiguration="SecureBasicRest"
              behaviorConfiguration="svcEndpoint" name="webHttp"
              contract="myservice.Imyservice" />
  </service>

您的想法是正确的,我们应该添加一个具有传输安全模式的服务端点。但是,服务名称应该是服务实现类的完全限定名称,而不是服务接口。

<service name="myservice.myservice"

如果问题仍然存在,请随时告诉我。


推荐阅读