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

相关文章:

  • 2022-12-23
  • 2021-11-06
  • 2021-05-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
猜你喜欢
  • 2021-05-30
  • 2022-12-23
  • 2021-10-31
  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2021-11-05
相关资源
相似解决方案