简体   繁体   中英

How to configure webHttp Binding while creating a WCF service in Azure?

I am developing a WCF WebRole service in Azure and need to invoke a method that to give employee data in JSON format.But unlike a normal WCF Web Service, I dont know how to configure the "Web.config" for WCF Webrole and my code "Web.config" for normal WCF service is below:

<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>

And my code "Web.config"for WCF WebRole (Azure)is as follow

<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>

Now I need to get the URI access "http://localhost/Service1.svc/GetId" where it should respond in JSON data. But for me it is showing that "HTTP400 Bad Request". Help me out.

The bad request might be that the request being sent is not valid. If your service was not accessible or found it would have been a different Http error code. Try enabling tracing on your service to see the cause for bad request. To enable tracing follow this link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM