WCF服务和AspNetCompatibilityEnabled ="true"导致请求错误

Chr*_*lls 2 asp.net wcf json jsonp

我有一个WCF服务定义为:

[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class Service
{
    [OperationContract]
    [WebGet(ResponseFormat = WebMessageFormat.Json)]
    public string HelloWorld()
    {
        return "Hello World";
    }
}
Run Code Online (Sandbox Code Playgroud)

我的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>
Run Code Online (Sandbox Code Playgroud)

我希望能够在我的WCF服务中访问ASP .Net会话变量,并且我希望WCF服务返回JSONP数据,但是即使使用这个简单的服务,浏览到../Service.svc/HelloWorld我得到了一个400 Bad Request错误.

有人能指出我正确的方向吗?

Dav*_*ter 5

看起来这个 Microsoft论坛不支持JSONP,ASP.NET兼容性和经过身份验证的用户的组合.

根据论坛的主持人,您需要禁用三者中的一个.

可能不是你希望的答案,但主持人的解释非常好,并提供了一些建议.

希望这可以帮助.祝好运!