AspNetCompatibilityRequirementsMode.Allowed)] public class CostService { // To use HTTP GET, add [WebGet ResponseFormat is WebMessageFormat.Json) // To create an operation that returns XML, // add [WebGet UpdateEmployee(Employee employee) { return; } [OperationContract] [WebGet ResponseFormat is WebMessageFormat.Json) // To create an operation that returns XML, // add [WebGet UpdateEmployee(Employee employee) { return; } [OperationContract] [WebGet
so, the service will be available at http://www.example.com/soap http://www.example.com/json Apply [WebGet operation contract to make it RESTful. e.g. public interface ITestService { [OperationContract] [WebGet ServiceContract(Namespace = "http://test")] public interface ITestService { [OperationContract] [WebGet
java.util.regex.Pattern; /** * 网页抓取 * @author 胡阳 * @blog http://www.the5fire.com * */ public class WebGet contextAll = new StringBuilder(""); private int pageCount = 0; private String pageType = ""; public WebGet () { } public WebGet(String url) { this.myUrl = url; } public WebGet(String url,int pageCount return contextAll.toString(); } public static void main(String[] args) throws IOException { WebGet wg = new WebGet("http://www.tianyabook.com/qita/hougeixue/",227,"html"); try { if (wg.writeTxt(
ServiceContract(Namespace = "http://www.artech.com/")] 2: public interface ICalculator 3: { 4: [WebGet = webGet) ? = 20: webGet)? (UriTemplate = "Add/{x}/{y}")] 5: double Add(double x, double y); 6: 7: [WebGet(UriTemplate = "Multiply/{x}/{y}")] 11: double Multiply(double x, double y); 12: 13: [WebGet(UriTemplate
图1-6 运行结果 (3)打开webget.cc文件,将代码修改,如图1-7所示。代码源码见附录。 图1-7 代码细节 (4)输入make进行编译,编译结果如图1-8所示。 /apps/webget cs144.keithw.org /hello 进行测试,测试结果如图1-9所示。 . /apps/webget cs144.keithw.org /hello 图1-9 测试结果 (6)输入make check_webget测试样例,测试结果如图1-10所示。 make check_webget 图1-10 测试结果 3 实现内存中的可靠字节流 (1)输入命令”.. 这里在webget.cc文件首先需要创建一个TCPSocket,只要管道未关闭就需要从管道内提取发送的消息,所以这里使用了while循环进行判断,直到eof结束,这里需要注意空格,特别容易出错。
本节我们将写一个“webget”程序,创建一个TCP stream socket,去和一个web server建立连接。 FileDescriptor, Socket, TCPSocket, and Address classes 各个类的继承关系如下: 看上去比较重要的是TCPSocket这个类,读完文档之后,我们就可以去实现webget 程序了,代码量预计 10 行左右,位于apps/webget.cc,实现代码时务必借助 libsponge 中的 TCPSocket 和 Address 类来完成。 /apps/webget cs144.keithw.org /hello 它的行为应该和上述2.1小节的行为保持一致。 最后它应该能够通过测试 make check_webget ---- In-memory reliable byte stream 要求 字节流可以从写入端写入,并以相同的顺序,从读取端读取 字节流是有限的
1: [ServiceContract] 2: public interface IEmployees 3: { 4: [WebGet(UriTemplate = "all") ] 5: [Description("获取所有员工列表")] 6: IEnumerable<Employee> GetAll(); 7: 8: [WebGet 1: [ServiceContract] 2: public interface IEmployees 3: { 4: //其他成员 5: [WebGet(UriTemplate
.85).aspx [ServiceContract] public interface IImageServer { [OperationContract, WebGet
Client》 下面我们来看一个简单的例子: [ServiceContract] public interface IService { [OperationContract] [WebGet
WCF Data Service 的.NET Client 的不支持返回值为原生类型(string,int)的服务操作调用,例如我们用如下服务操作: [WebGet] public ObjectQuery
2 { 3 [ServiceContract(Namespace = "http://www.sory.com")] 4 public interface IEmployees 5 { 6 [WebGet (UriTemplate="all")] 7 IEnumerable<Employee> GetAll(); 8 9 [WebGet(UriTemplate = "{id}")] 10 Employee
ContactApi类,添加下述引用: using System.ServiceModel.Web; using ContactManager.Resources; 添加一个Get方法返回所有的contracts [WebGet Contact {ContactId = 6, Name = "Yavor Georgiev"} }; return contacts.AsQueryable(); } Get方法上加了WebGet
创建用于测试的契约接口: [ServiceContract] public interface IService1 { [OperationContract] [WebGet
RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class WcfTreeService { // 添加 [WebGet
接口代码 namespace WCFLib { [ServiceContract] public interface IRestService { [WebGet
5: { 6: [ServiceContract] 7: public interface IEmployees 8: { 9: [WebGet
ServiceContract(Namespace="http://www.artech.com/")] 2: public interface IEmployees 3: { 4: [WebGet (UriTemplate = "all")] 5: IEnumerable<Employee> GetAll(); 6: 7: [WebGet(UriTemplate
(Namespace = "http://www.artech.com/")] 7: public interface ITime 8: { 9: [WebGet
支持HTTP GET和POST,分别对应使用 [WebGet] 和 [WebInvoke] 特性。 如果需要支持其他HTTP动词,你需要在.svc文件中针对需要支持的HTTP动词做一些配置。 使用WebGet通过参数传递数据,需要配置。同时,UriTemplate 必须指定。 支持XML, JSON 和 ATOM 数据格式。
(Namespace = "http://www.artech.com/")] 7: public interface ITime 8: { 9: [WebGet