http://www.cnblogs.com/quietwalk/archive/2011/08/09/2132573.html

http://www.cnblogs.com/huangxincheng/p/4609168.html

http://www.cnblogs.com/VinC/archive/2011/02/25/Use-GSon-Hand-JsonData-For-Android-Device.html

如何在调用WCF服务之前弹出一个确认对话框?

数据契约:存在于SOAP的BODY部分

应用场景:传输类实体

消息契约:提供完整的SOAP

构建(SOAP)头、体(应用场景:上传文件)

WCF元数据公布的2种方式:httpGetEnabled与mex

WCF元数据发布的2种方式:httpGetEnabled与mex
一、元数据即WSDL,描述了服务的细节,以便客户端使用。

二、必须为服务配置ServiceMetadata行为,才能为其生成WSDL,才能再使用httpGetEnabled或mex将其公布出去

三、这两种方式公布出去的WSDL无区别。但公布的方式有区别
1、httpGetEnabled=true,类似的还有httpsGetEnabled=true
此方式通过在服务在的URL后加“?wsdl”的方式公布WSDL,可直接通过HTTP访问得到。

2、mex
此方式以一般的终结点方式公布,支持各种协议:http、tcp、NamedPipe

告别烦恼的config配置

---------------------------------------------------------------------------------------

<configuration>
<appSettings>
<add key ="baseurl" value="http://localhost:19200/HomeService"/>
<add key ="endpoindurl" value="net.tcp://localhost:1920/HomeService"/>
</appSettings>

服务端

class Program1
{
static void Main(string[] args)
{
ServiceHost host = new ServiceHost(typeof(HomeService), new Uri(ConfigurationManager.AppSettings["baseurl"])); host.AddServiceEndpoint(typeof(IHomeService), new NetTcpBinding(), ConfigurationManager.AppSettings["endpoindurl"]); //公布元数据
host.Description.Behaviors.Add(new ServiceMetadataBehavior() { HttpGetEnabled = true });
host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex"); host.Open(); Console.WriteLine("服务已经开启。。。"); Console.Read();
}
}

客户端

static void Main(string[] args)
{
ChannelFactory<IHomeService> factory = new ChannelFactory<IHomeService>(new NetTcpBinding(), "net.tcp://localhost:1920/homeservice"); var channel = factory.CreateChannel(); var result = channel.GetLength("");
}

----------------------------------------------------------------------------------------

WebGet和WebInvoke正是用了UriTemplate,才具有了路由转向的功能,还有就是默认返回的是xml,这里就用json值作为服务返回的格式

[ServiceContract]
public interface IHomeService
{
[OperationContract]
[WebGet(UriTemplate = "Get/{id}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Student Get(string id); [OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "Add", RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
string Add(Student stu);
}
<?xml version="1.0" encoding="utf-8"?>
<configuration> <system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="ActivityTracing">
<listeners>
<add name="mylisteners" type="System.Diagnostics.XmlWriterTraceListener" initializeData="E:\1.txt" />
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="ActivityTracing">
<listeners>
<add name="messagelogging" type="System.Diagnostics.XmlWriterTraceListener" initializeData="E:\2.txt"/>
</listeners>
</source>
</sources>
<trace autoflush="true"/>
</system.diagnostics> <system.serviceModel> <diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtTransportLevel="true" />
</diagnostics> <behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webbehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors> <services>
<service name="MyService.HomeService">
<endpoint address="HomeService" binding="webHttpBinding" behaviorConfiguration="webbehavior"
contract="MyService.IHomeService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://127.0.0.1:1920" />
</baseAddresses>
</host>
</service>
</services> </system.serviceModel> </configuration>

------------------------------------------------------------------------------------------

自定义FaultException

public class HomeService : IHomeService
{
public Student Get(string id)
{
try
{
//这里必然会抛出异常。。。
var result = Convert.ToInt32(id) / Convert.ToInt32(""); return new Student() { ID = Convert.ToInt32(id), Name = "hxc", SNS = "" };
}
catch (Exception ex)
{
var reason = new FaultReason("你这个战斗力只有五的渣渣。。。 这么简单的错误都出来了,搞个鸡巴毛"); var code = new FaultCode(""); var faultException = new FaultException(reason, code, "是Get这个王八蛋"); throw faultException;
}
}
}

-------------------------------------------------------------------------------------------

数据传输量,传输量不能大于64k,否则请求就会在client端拒绝

 <bindings>
<netTcpBinding>
<binding name="MySessionBinding" maxReceivedMessageSize="2147483647"/>
</netTcpBinding>
</bindings>

使用MaxBufferSize 和 MaxBufferPoolSize,就是用来增加缓冲区和缓冲池的大小。

当并发数达到800左右的时候,servcie端就开始拒绝client端过来的请求了,并且之后的1min的时间里,client端开始出现超时异常,在wcf里面有一个叫做ServiceThrottlingElement绑定元素,它就是用来控制服务端的并发数

<system.serviceModel>
<behaviors >
<serviceBehaviors >
<behavior name="nettcpBehavior">
<serviceMetadata httpGetEnabled="false" />
<!--是否在错误中包含有关异常的详细信息-->
<serviceDebug includeExceptionDetailInFaults="True" />
<serviceThrottling maxConcurrentCalls="2147483647" maxConcurrentInstances="2147483647" maxConcurrentSessions="2147483647" />
</behavior>
</serviceBehaviors>
</behaviors> <bindings>
<netTcpBinding>
<binding name="MySessionBinding" />
</netTcpBinding>
</bindings> <services>
<service behaviorConfiguration="nettcpBehavior" name="MyService.HomeService">
<endpoint address="net.tcp://127.0.0.1:19200/HomeService" binding="netTcpBinding"
bindingConfiguration="MySessionBinding" contract="MyService.IHomeService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://127.0.0.1:1920" />
</baseAddresses>
</host>
</service>
</services> </system.serviceModel>

-------------------------------------------------------------------------------------------

其实Binding就是一个预先默认配置好的信道栈,每一种Binding都有属于自己的BindingElements,

恰恰这些Elements是可以跨Binding的,也就是说可以自由组合Elements,这样可以最大的灵活性,例如:

BasicHttpBinding有两个绑定元素,其中对soap消息进行的是TextMessageEncoding编码对吧,而netTcpBinding对soap进行的BinaryMessageEncoding。

自定义绑定:

class Program1
{
static void Main(string[] args)
{
ServiceHost host = new ServiceHost(typeof(HomeService), new Uri("http://192.168.1.105:1920")); var customBinding = new CustomBinding(); customBinding.Elements.Add(new BinaryMessageEncodingBindingElement());
customBinding.Elements.Add(new HttpTransportBindingElement()); host.AddServiceEndpoint(typeof(IHomeService), customBinding, "HomeServie"); host.Description.Behaviors.Add(new ServiceMetadataBehavior() { HttpGetEnabled = true }); host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex"); host.Open(); Console.WriteLine("服务已经开启!!!"); Console.Read();
}
}

------------------------------------------------------------------------------------------

高级玩法之自定义Behavior

你必须要了解的3种通信模式

你需要了解的三个小技巧   服务是端点的集合 Host寄宿多个Service  Tcp中的端口共享

通信单元Message

client如何知道server提供的功能清单 wsdl

------------------------------------------------------------------------------------------

MongoDB 是由C++语言编写的,是一个基于分布式文件存储的开源数据库系统。

在高负载的情况下,添加更多的节点,可以保证服务器性能。

MongoDB 旨在为WEB应用提供可扩展的高性能数据存储解决方案。

MongoDB 将数据存储为一个文档,数据结构由键值(key=>value)对组成。MongoDB 文档类似于 JSON 对象。字段值可以包含其他文档,数组及文档数组。

http://blog.csdn.net/u011630900/article/details/52926363

WCF、MongoDB的更多相关文章

  1. 关于 redis、memcache、mongoDB 的对比

    从以下几个维度,对 redis.memcache.mongoDB 做了对比. 1.性能 都比较高,性能对我们来说应该都不是瓶颈. 总体来讲,TPS 方面 redis 和 memcache 差不多,要大 ...

  2. MySQL、MongoDB、Redis数据库Docker镜像制作

    MySQL.MongoDB.Redis数据库Docker镜像制作 在多台主机上进行数据库部署时,如果使用传统的MySQL的交互式的安装方式将会重复很多遍.如果做成镜像,那么我们只需要make once ...

  3. Node.js、express、mongodb 实现分页查询、条件搜索

    前言 在上一篇Node.js.express.mongodb 入门(基于easyui datagrid增删改查) 的基础上实现了分页查询.带条件搜索. 实现效果 1.列表第一页. 2.列表第二页 3. ...

  4. Node.js、express、mongodb 入门(基于easyui datagrid增删改查)

    前言 从在本机(win8.1)环境安装相关环境到做完这个demo大概不到两周时间,刚开始只是在本机安装环境并没有敲个Demo,从周末开始断断续续的想写一个,按照惯性思维就写一个增删改查吧,一方面是体验 ...

  5. redis、memcache、mongoDB 做了对比

    from: http://yang.u85.us/memcache_redis_mongodb.pdf   从以下几个维度,对redis.memcache.mongoDB 做了对比. 1.性能 都比较 ...

  6. 转:WCF、WebAPI、WCFREST、WebService之间的区别

    WCF.WebAPI.WCFREST.WebService之间的区别   注明:转载 在.net平台下,有大量的技术让你创建一个HTTP服务,像Web Service,WCF,现在又出了Web API ...

  7. redis、memcached、mongoDB 对比与安装

    一.redis.memcached.mongoDB 对比 Memcached 和 Redis都是内存型数据库,数据保存在内存中,通过tcp直接存取,速度快,并发高.Mongodb是文档型的非关系型数据 ...

  8. WCF 、Web API 、 WCF REST 和 Web Service 的区别

    WCF .Web API . WCF REST 和 Web Service 的区别 The .Net framework has a number of technologies that allow ...

  9. 数据库高可用架构(MySQL、Oracle、MongoDB、Redis)

    一.MySQL MySQL小型高可用架构 方案:MySQL双主.主从 + Keepalived主从自动切换   服务器资源:两台PC Server 优点:架构简单,节省资源 缺点:无法线性扩展,主从失 ...

随机推荐

  1. c# winform编程之多线程ui界面资源修改总结篇

    单线程的winfom程序中,设置一个控件的值是很easy的事情,直接 this.TextBox1.value = "Hello World!";就搞定了,但是如果在一个新线程中这么 ...

  2. Oracle ORA-01722: 无效数字 处理方法

    C# + Oralce 10G 项目中 有用参数处理Update语句.参数命名和表字段同名.执行报错: ORA-01722: 无效数字 后修改所有的参数和对应字段不同.解决. 修改前: StringB ...

  3. Unity学习疑问记录之界面适配

    Unity3d UGUI 界面适配 实例解析 三种适配方式 http://www.mamicode.com/info-detail-475563.html

  4. 返回数据方法DeaCacheCommand,由CRL自动实现

    越来越多的人学起了前端,或许部分的初衷仅是它简单易上手以及好找工作,毕竟几年前只会个html和css就能有工作,悄悄告诉泥萌,这也是博主一年前的初衷 还好numpy, scikit-learn都提供了 ...

  5. Azure Active Directory Connect密码同步问题

    这几天一直在弄O365与本地域账号的密码同步问题.由于微软即将用Azure Active Directory Connect(以下简称AADC)这个同步工具替代之前的DirSync,所以我也研究了下这 ...

  6. php实现网页trace方法

    // 记录内存初始使用和开始时间,在系统的入口记录 $beginTime= microtime(TRUE); $start_memory = memory_get_usage(); //die; ec ...

  7. hadoop意外之旅--巧合遇到一只大象

    公司面临转型,所有开发也难免面临转型,开始选择自己想要走的方向进行研究. 说来也巧合,最近正好说搭个hadoop环境玩玩,结果遇到转型还被选为大数据小组组长.(尴尬) 开始一场遇到大象之旅,希望能在这 ...

  8. ECMAScript Web APIs node.js

    https://hacks.mozilla.org/2015/04/es6-in-depth-an-introduction/ What falls under the scope of ECMASc ...

  9. 上传图片插件鼠标手cursor:pointer;不生效

    问题: 只在谷歌里失效; 解决: font-size:0; 参考: http://jingyan.baidu.com/article/48b558e32fabb67f38c09a81.html htt ...

  10. GIT 配置管理

    git版本控制开发流程小结笔记(一) 收藏                                                                     何良瑞Nyanko君 ...