从浏览器调用JSON Rest服务

时间:2020-05-11 22:38:13

标签: rest wcf https

想在我的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" />

1 个答案:

答案 0 :(得分:0)

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

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

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

<service name="myservice.myservice"

请随时让我知道问题是否仍然存在。