【问题标题】:How to configure webHttp Binding while creating a WCF service in Azure?在 Azure 中创建 WCF 服务时如何配置 webHttp 绑定?
【发布时间】:2012-01-04 14:28:46
【问题描述】:

我正在 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 错误请求”。帮帮我。

【问题讨论】:

  • 你在哪里打电话? “localhost”是指您的本地,呃,主机;如果你想调用你的 Azure 服务,你需要替换你分配给它的主机名。
  • 嗨,我只在本地主机中调用此服务。而且我只使用计算模拟器,没有 Azure 订阅。

标签: c# wcf azure


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2011-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-29
    • 2015-11-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多