摘要:环境:jquery1.8.1+Wcf(IIS托管)错误:405错误(方法不被允许)原因:ajax跨域调用错误解决办法:1.在发布WCF上面允许crossDomainScriptAccessEnabled<system.serviceModel> <behaviors> <endpointBehaviors> <behavior name="JSONPAspNetAjaxBehavior"> <enableWebScript /> </behavior> ...
阅读全文
摘要:最近有个内部系统要对外公开,要开启https ,所有模块都正常运行,但偏偏服务层出问题了。The HttpGetEnabled property of ServiceMetadataBehavior is set to true and the HttpGetUrl property is a relative address, but there is no http base address. Either supply an http base address or set HttpGetUrl to an absolute address.从上面的字面告诉我们,元数据被设置true .
阅读全文
摘要:我们在.NET 4.0当中调用JS+WCF 一般都是这样做: <system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" > <serviceActivations> <add relativeAddress="OrderGetService.svc" service="OrderGetService"
阅读全文
摘要:我有一组产品 我要获取总价,一般正常情况都是使用设计模式之策略模式来搞定,非常简单。但我们这里要Ioc工具-Ninject,那我们就得写很多接口了。 /// <summary> /// 正常价格 /// </summary> public interface INormal { /// <summary> /// 返回价格总数 /// </summary> /// <param name="products"></param> /// <returns></returns> de
阅读全文
摘要:上一篇,我们介绍了如何使用JS去调用WCF。但实际开发中,各大网站的API都是REST风格,那我们也REST下,顺便用JS调用。废话不多说,我就把几个比较重要的代码贴下:接口:using System.ServiceModel;using System.ServiceModel.Web;[ServiceContract]public interface IproductService{ [WebGet(UriTemplate = "all", ResponseFormat = WebMessageFormat.Json)] //不设置这个 默认就是xml IEnumerab
阅读全文
摘要:上一篇,我们介绍使用WCF代替传统的WebService. 那么代替的话 我们客户端用JS也应该可以调用。.net4.0中我们不仅可以调用,还可以很简单的调用。代码如下:服务端:using System.ServiceModel.Activation; //这个告诉我们是否动态加载ServiceHost宿主//要以IIS管道运行WCF服务 只需要加上这个特性就可以 运行网站的同时 运行WCF服务 AJAX也可以请求到了[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.All
阅读全文
摘要:大家在开发webform的时候webService 一直什么拿手好戏。但.net4.0 出现以后,我们完全可以用Wcf 代替传统的WebService.跟我们平时一样引用webservice一样,引用Wcf 服务。我们还是 按 服务接口-》服务-》客户端服务接口:using System;using System.Collections.Generic;using System.Runtime.Serialization;using System.ServiceModel;using System.Text;/* *顺便说下 这里的NameSpace 必须和数据契约的NameSpace一致 否
阅读全文
摘要:上两篇,我们介绍了.net3.5 使用WCF一些配置,但到了.NET4.0版本以后,使用WCF就更加简洁了。简洁在那里,当然这服务端的ABC配置,新的特性可以使用默认特性,我们无需再写ABC配置了,如果有意外到是可以配置的。服务端代码如下:using System.ServiceModel;using Wcf.IProductService;namespace Server{ class Program { static void Main(string[] args) { //这里就利用.net4.0 新特性 使用默认总结点 不用...
阅读全文
摘要:上面我介绍了在.NET(3.0/3.5)开发WCF的使用示例。这篇,我将讲解Rest 这个炙手可热的新的开发方式,至于rest 是什么,请大家百度下。我们还是以下面的方式做示例:服务接口-》服务-》客户端1.服务接口:数据接口using System.ServiceModel;using System.ServiceModel.Web; //这里就是REST 要关键引用的类using System.Runtime.Serialization;namespace Wcf.IProductService{ [ServiceContract] public interface IProd...
阅读全文
摘要:WCF目前使用越来越多了,但根据不同的.NET版本,会不同的使用方式。首先,我们在.NET(3.0/3.5)开发WCF的使用示例。服务接口-》服务-》客户端。 也就是最常用的开发方式,也是最多的开发方式。1.服务接口:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.ServiceModel;namespace WCF.IServiceAPI{ /// <summary> /// 服务接口 /// </summary> [Servi
阅读全文