【发布时间】: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 订阅。