zoukankan      html  css  js  c++  java
  • JQuery Ajax调用WCF实例以及遇到的问题

    1.遇到的最多的问题就是跨域问题,这个时间需要我们添加如下代码解决跨域的问题

    第一步:在服务类加Attribute

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

    第二步:在构造函数中添加

    if (WebOperationContext.Current != null)
    {
          WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
          WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    }

    2.如何暴漏在WCF中使用的实体、枚举等的于客户端中

    在服务接口中添加如下Attribute

    [ServiceKnownType(typeof(类型))]

    在服务接口的实现类中添加如下Attribute

    [KnownType(typeof(类型))]

    3.设置WCF服务方法返回的类型

    [WebInvoke(Method = "*", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]

    代码文件会在后续中陆续提供,敬请关注

    联系我hornet_team@sina.com

  • 相关阅读:
    SpringMVC拦截器
    SpringMVC异常
    SpringMVC文件上传
    SpringMVC返回值类型
    JVM字节码
    使用Apache JMeter进行测试
    Tomcat优化
    垃圾收集器
    GC常见算法
    VisualVM远程连接Tomcat
  • 原文地址:https://www.cnblogs.com/hornet/p/4130672.html
Copyright © 2011-2022 走看看