如何在Azure中创建WCF服务时配置webHttp绑定?

时间:2012-01-04 14:28:46

标签: c# wcf azure

我正在开发Azure中的WCF WebRole服务,需要调用一种方法来提供JSON格式的员工数据。但与普通的WCF Web服务不同,我不知道如何为WCF Webrole配置“Web.config”我的正常WCF服务的代码“Web.config”如下:

<system.serviceModel>
<services>
  <service name="empl.Service1" behaviorConfiguration="empl.Service1Behavior">
    <!-- Service Endpoints -->
    <endpoint  address="" binding="webHttpBinding" contract="empl.IService1" behaviorConfiguration="web">
      <!-- 
          Upon deployment, the following identity element should be removed or replaced to reflect the 
          identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
          automatically.
      -->
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="web">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="empl.Service1Behavior">
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

我的WCF WebRole(Azure)代码“Web.config”如下

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /></system.serviceModel>

现在我需要获取URI访问权限“http://localhost/Service1.svc/GetId”,它应该在JSON数据中进行响应。但对我来说,它显示“HTTP400 Bad Request”。帮助我。

1 个答案:

答案 0 :(得分:0)

错误请求可能是发送的请求无效。如果您的服务无法访问或发现它将是一个不同的Http错误代码。尝试启用对服务的跟踪,以查看错误请求的原因。要启用跟踪,请遵循此link