【发布时间】:2012-09-12 05:31:58
【问题描述】:
我有一个 WCF 服务定义为:
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class Service
{
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
public string HelloWorld()
{
return "Hello World";
}
}
我的 Web.Config 文件:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true"/>
</webHttpBinding>
</bindings>
<services>
<service name="Service">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP" contract="Service" behaviorConfiguration="webHttpBehavior"/>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>
</system.serviceModel>
</configuration>
我希望能够访问我的 WCF 服务中的 ASP .Net 会话变量,并且我希望 WCF 服务返回 JSONP 数据,但是即使使用这个简单的服务,浏览到 ../Service.svc/HelloWorld 我收到 400 Bad Request 错误。
有人能指出正确的方向吗?
【问题讨论】:
-
详细的错误信息是什么?可能是您的绑定的某些部分不支持 ASP.Net 兼容性。
-
服务器在处理请求时遇到错误。异常消息是“经过身份验证的服务不支持跨域 javascript 回调。”