1、能被ajax get

2、能post

3、wcf正常调用

实现:

  1. [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
  2. [JavascriptCallbackBehavior(UrlParameterName = "jsoncallback")]
  3. public class WCFJsonTest : IWCFJsonTest
  4. {
  5.  
  6. public List<TestModel> GetTest(string id)
  7. {
  8. List<TestModel> list = new List<TestModel>();
  9. TestModel t = new TestModel();
  10. t.Ids = ;
  11. t.Names = id;
  12. list.Add(t);
  13.  
  14. TestModel t1 = new TestModel();
  15. t1.Ids = ;
  16. t1.Names = id+"_"+Guid.NewGuid().ToString();
  17. list.Add(t1);
  18.  
  19. return list;
  20. }
  21.  
  22. public TestModel PostTest(string id, string name)
  23. {
  24. TestModel t1 = new TestModel();
  25. t1.Ids = int.Parse(id);
  26. t1.Names = name + "_" + Guid.NewGuid().ToString();
  27. return t1;
  28. }
  29.  
  30. public TestModel PostTest1(TestModel model)
  31. {
  32. TestModel t1 = new TestModel();
  33. t1.Ids = model.Ids;
  34. t1.Names = model.Names + "_" + Guid.NewGuid().ToString();
  35. return t1;
  36. }
  37. }

接口:

  1. [ServiceContract]
  2.  
  3. public interface IWCFJsonTest
  4. {
  5. [OperationContract]
  6. [WebGet(UriTemplate = "/GetTest/{id}", ResponseFormat = WebMessageFormat.Json)]
  7. List<TestModel> GetTest(string id);
  8.  
  9. [OperationContract]
  10. [WebInvoke(Method="GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
  11. TestModel PostTest(string id, string name);
  12.  
  13. [OperationContract]
  14. [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
  15. TestModel PostTest1(TestModel model);
  16. }

配置:

endpoint配置两个一个web使用webHttpBinding,一个给wcf

  1. <system.serviceModel>
  2. <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
  3. <services>
  4. <service name="BLL.WCFJsonTest" behaviorConfiguration="AllBehavior" >
  5. <endpoint contract="IBLL.IWCFJsonTest" binding="wsHttpBinding" bindingConfiguration="WsHttpBinding_TEST" address="wcf" />
  6. <endpoint kind="webHttpEndpoint" contract="IBLL.IWCFJsonTest" binding="webHttpBinding" bindingConfiguration="basicTransport" behaviorConfiguration="web" address="" />
  7. <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
  8. </service>
  9. </services>
  10.  
  11. <behaviors>
  12. <serviceBehaviors>
  13. <behavior name="AllBehavior">
  14. <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
  15. <serviceDebug includeExceptionDetailInFaults="true" />
  16. </behavior>
  17. <behavior name="">
  18. <serviceMetadata httpGetEnabled="true" />
  19. <serviceDebug includeExceptionDetailInFaults="false" />
  20. </behavior>
  21. </serviceBehaviors>
  22. <endpointBehaviors>
  23. <behavior name="web">
  24. <webHttp helpEnabled="true"/>
  25. </behavior>
  26. </endpointBehaviors>
  27. </behaviors>
  28. <bindings>
  29. <webHttpBinding>
  30. <binding name="basicTransport" crossDomainScriptAccessEnabled="true"/>
  31. </webHttpBinding>
  32. <wsHttpBinding>
  33. <binding name="WsHttpBinding_TEST" closeTimeout="00:01:00"
  34. openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
  35. allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
  36. maxBufferPoolSize="" maxReceivedMessageSize=""
  37. messageEncoding="Text" textEncoding="utf-8"
  38. useDefaultWebProxy="true">
  39. <readerQuotas maxDepth="" maxStringContentLength="" maxArrayLength=""
  40. maxBytesPerRead="" maxNameTableCharCount="" />
  41. <security mode="None">
  42. <transport clientCredentialType="None" proxyCredentialType="None"
  43. realm="" />
  44. <message clientCredentialType="UserName" algorithmSuite="Default" />
  45. </security>
  46. </binding>
  47. </wsHttpBinding>
  48. </bindings>
  49. <standardEndpoints>
  50. <webHttpEndpoint>
  51. <standardEndpoint crossDomainScriptAccessEnabled="true"/>
  52. </webHttpEndpoint>
  53. </standardEndpoints>
  54. </system.serviceModel>

调用:

wcf正常调用地址:http://xxxxxx:xxxx/JsonTestService.svc

post:http://xxxxxx:xxxx/JsonTestService.svc/PostTest

get:http://xxxxxx:xxxx/JsonTestService.svc/GetTest/2

例如:

  1. string srcString=GetData("", "http://xxxxxx:xxxx/JsonTestService.svc/GetTest/2");
  2.  
  3. srcString = PostHelper.GetPermissionRemoteData("http://xxxxxx:xxxx/JsonTestService.svc/PostTest","{\"id\":\"10\",\"name\":\"张三\"}","text/json");
  4.  
  5. string jsonStr = "{\"Ids\":\"10\",\"Names\":\"张三1\"}";
  6. srcString = PostHelper.GetPermissionRemoteData("http://xxxxxx:xxxx/JsonTestService.svc/PostTest1", "{\"model\": "+ jsonStr+" }", "text/json");
  7.  
  8. WCFJsonTestClient client = new WCFJsonTestClient();
  9. var r = client.GetTest("");
  10. var r1 = client.PostTest("", "a");
  11. var r2 = client.PostTest1(new TestModel() { Ids = , Names = "" });
  1. $.ajax({
  2. type: "GET",
  3. dataType: "jsonp",
  4. url: 'http://xxxxxx:xxxx/JsonTestService.svc/GetTest/2',
  5. success: function (data) {
  6. console.log(data);
  7. },
  8. error: function (XMLHttpRequest, textStatus, errorThrown) {
  9. console.log('err1' + XMLHttpRequest);
  10. console.log('err2' + textStatus);
  11. console.log('err3' + errorThrown);
  12. }
  13. });

WCF多种调用方式兼容的更多相关文章

  1. Android开发中怎样调用系统Email发送邮件(多种调用方式)

    在Android中调用其他程序进行相关处理,几乎都是使用的Intent,所以,Email也不例外,所谓的调用Email,只是说Email可以接收Intent并做这些事情 我们都知道,在Android中 ...

  2. WCF服务调用方式

    WCF服务调用通过两种常用的方式:一种是借助代码生成工具SvcUtil.exe或者添加服务引用的方式,一种是通过ChannelFactory直接创建服务代理对象进行服务调用.

  3. Spring MVC一个方法适用多种调用方式

    web.xml spring-mvc.xml <mvc:annotation-driven /> <context:component-scan base-package=" ...

  4. Wcf:可配置的服务调用方式

    添加wcf服务引用时,vs.net本来就会帮我们在app.config/web.config里生成各种配置,这没啥好研究的,但本文谈到的配置并不是这个.先看下面的图: 通常,如果采用.NET的WCF技 ...

  5. SOFA 源码分析 — 调用方式

    前言 SOFARPC 提供了多种调用方式满足不同的场景. 例如,同步阻塞调用:异步 future 调用,Callback 回调调用,Oneway 调用. 每种调用模式都有对应的场景.类似于单进程中的调 ...

  6. Wcf调用方式

    C#动态调用WCF接口,两种方式任你选.   写在前面 接触WCF还是它在最初诞生之处,一个分布式应用的巨作. 从开始接触到现在断断续续,真正使用的项目少之又少,更谈不上深入WCF内部实现机制和原理去 ...

  7. C#高性能TCP服务的多种实现方式

    哎~~ 想想大部分园友应该对 "高性能" 字样更感兴趣,为了吸引眼球所以标题中一定要突出,其实我更喜欢的标题是<猴赛雷,C#编写TCP服务的花样姿势!>. 本篇文章的主 ...

  8. C#开发微信门户及应用(11)--微信菜单的多种表现方式介绍

    在前面一系列文章中,我们可以看到微信自定义菜单的重要性,可以说微信公众号账号中,菜单是用户的第一印象,我们要规划好这些菜单的内容,布局等信息.根据微信菜单的定义,我们可以看到,一般菜单主要分为两种,一 ...

  9. WCF初探-10:WCF客户端调用服务

    创建WCF 服务客户端应用程序需要执行下列步骤: 获取服务终结点的服务协定.绑定以及地址信息 使用该信息创建 WCF 客户端 调用操作 关闭该 WCF 客户端对象 WCF客户端调用服务存在以下特点: ...

随机推荐

  1. 【UML】类图的几种关系总结

    在UML类图中,常见的有以下几种关系:泛化(Generalization),  实现(Realization),关联(Association),聚合(Aggregation),组合(Compositi ...

  2. AT&T Assembly for Linux and Mac (sys_write)

    Write() in C : (sys_write.c) #include <stdio.h> int main(void) { printf("Hello Landpack\n ...

  3. paip.注册java程序为LINUX系统服务的总结。

    paip.注册java程序为LINUX系统服务的总结. ////////////////实现开机启动. 标准方法是按照/etc/init.d/下面的文件,修改一下:然后chkconfig xxx on ...

  4. 兼容iOS 10 资料整理

    1.Notification(通知) 自从Notification被引入之后,苹果就不断的更新优化,但这些更新优化只是小打小闹,直至现在iOS 10开始真正的进行大改重构,这让开发者也体会到UserN ...

  5. H608B无线路由破解方法

    家里的无线路由送人了,准备重新买,今日一看,竟然自带的猫(ZTE H608B)有wifi天线和4个LAN口,想着是支持路由功能的,那必然就是从软件上做了手脚.搜索该型号发现没人刷openwrt或者to ...

  6. IOS6屏幕旋转详解(自动旋转、手动旋转、兼容IOS6之前系统)

    转自 http://blog.csdn.net/zzfsuiye/article/details/8251060 概述: 在iOS6之前的版本中,通常使用 shouldAutorotateToInte ...

  7. SQL Server死锁

    SQL Server死锁 多个事务之间互相等待对方的资源,导致这些事务永久等待 注意是永久等待,而非长事务 死锁的4个条件 互斥条件(Mutual exclusion):资源不能被共享,只能由一个进程 ...

  8. LCLFramework框架 1.1 Pre-Alpha 源码公布

    使用开发框架的好处:1.框架在技术上为软件系统提供了完整的模式实践2.框架为团队提供了合理可行的软件开发过程模式3.框架的应用大大提高了团队的开发效率,团队只需要关注与领域相关的业务实现,而无需关注具 ...

  9. RabbitMQ学习笔记5-简单的RPC调用

    利用空的queue名字("")让rabbitMQ生成一个唯一的队列名称,同时指定队列是:临时的(auto-delete).私有的(exclusive). 在发送的RPC调用消息里设 ...

  10. Python: 收集所有命名参数

    有时候把Python函数调用的命名参数都收集到一个dict中可以更方便地做参数检查,或者直接由参数创建attribute等.更简单的理解就是def foo(*args, **kwargs): pass ...