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. maven模块

    用maven无它,唯方便而. 模块依赖可以用来做一些公共模块,多个工程调用. 先子模块 install 或者package.在父模块install

  2. The MESI Protocol

    COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION To provide cache cons ...

  3. 在命令行下使用perl

    http://blog.sina.com.cn/s/blog_4af3f0d20100g9oz.html aaa@domain.com  2aaa@domain.com 111bbb@home.com ...

  4. asp.net mvc中ViewData、ViewBag和TempData的详解

    一.ViewData和ViewBag 1.ViewData和ViewBag都是从Action向View传递数据的方式,当然还有其他方式如向View传递Model. 2.ViewData页面查询数据时需 ...

  5. http://www.cnblogs.com/holly8/p/6178828.html

    http://www.cnblogs.com/holly8/p/6178828.html

  6. LINQ教程

    在说LINQ之前必须先说说几个重要的C#语言特性 一:与LINQ有关的语言特性 1.隐式类型 (1)源起 在隐式类型出现之前, 我们在声明一个变量的时候, 总是要为一个变量指定他的类型 甚至在fore ...

  7. kdiff3的主窗口说明 Base Local Remote 分别代表什么分支

  8. C# 实现函数回调

    public class Lib { public delegate void UserFunctionCB(); private static UserFunctionCB m_userFnCB; ...

  9. 正则表达式/g与/i及/gi的意义

    g: 全局匹配 i: 忽略大小写 gi: 全局匹配 + 忽略大小写

  10. CSS深入理解之margin

      前言   改变容器尺寸   margin改变容器尺寸有以下两个限制条件: 使用于没有设置宽高的普通block元素float/absolute/fixed元素 以及 inlines水平 table- ...