簡體   English   中英

在Azure中創建WCF服務時如何配置webHttp綁定?

[英]How to configure webHttp Binding while creating a WCF service in 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錯誤請求”。 幫幫我。

錯誤的請求可能是所發送的請求無效。 如果無法訪問或發現您的服務,則可能是其他Http錯誤代碼。 嘗試對您的服務啟用跟蹤,以查看請求錯誤的原因。 要啟用跟蹤,請點擊此鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM