asp.net - WCF 服务和 AspNetCompatibilityEnabled ="true"导致请求错误

标签 asp.net json wcf jsonp

我有一个 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 session 变量,并且我希望 WCF 服务返回 JSONP 数据,但是即使使用这个简单的服务,浏览到 ../Service.svc/HelloWorld I我收到 400 Bad Request 错误。

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

最佳答案

根据 this,似乎不支持 JSONP、ASP.NET 兼容性和经过身份验证的用户的组合微软论坛。

根据论坛版主的说法,您需要禁用这三个中的一个。

可能不是你想要的答案,但版主的解释很好,并提供了一些建议。

希望这对您有所帮助。祝你好运!

关于asp.net - WCF 服务和 AspNetCompatibilityEnabled ="true"导致请求错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12502649/

相关文章:

c# - 使用列表的 ASP.Net 随机生成器

c# - 如何覆盖 BoundField 的 Itemstyle-width?

asp.net - 从 jQuery 调用 ASP.NET ASMX Web 服务

wcf - 在 Visual Studio 中测试 WSDL

wcf - 使用多个架构文件和 <includes> 发布 Biztalk WCF 服务

jquery - 在asp.net类库中使用ckeditor

javascript - 使 cookie 过期

javascript - 为什么这是指外部变量?

java - jackson 处理接口(interface)

c# - 什么作为 Web 引用 (ASMX) 应该作为服务引用 (WCF),对吗?