Webservices-2.C#创建web服务,及引用访问、代码访问
注:web服务简介Webservices-1.web服务定义简介
以下均以C#语言为例
一、创建web服务(简单介绍,主要讨论客户端引用)
打开VS创建网站项目,在网站项目中添加“WEB服务(ASMX)”,
此时VS便已经默认建立好一个web服务。
如需使用Session,请添加“[WebMethod(EnableSession=true)] ”,更多信息请实际编写代码时候查看智能提示,及msdn文档
此时可以将服务部署于web服务器上,以IIS为例,部署完毕即可正确访问。有时创建IIS网站时,请注意配置使用的.net版本库。
访问地址:http://172.168.0.40:8086/WebSer.asmx(个人PC示例,请勿随意copy)
二、服务解析概述
在访问地址后添加?WSDL既可以查看服务说明文档:http://172.168.0.40:8086/WebSer.asmx?WSDL
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="ChineShine" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="ChineShine" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="ChineShine">
<s:element name="HelloWorld">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="ss" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="HelloWorldResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="NoReturnValue">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="ss" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="NoReturnValueResponse">
<s:complexType />
</s:element>
<s:element name="NoParaValue">
<s:complexType />
</s:element>
<s:element name="NoParaValueResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="NoParaValueResult" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="HelloWorldSoapIn">
<wsdl:part name="parameters" element="tns:HelloWorld" />
</wsdl:message>
<wsdl:message name="HelloWorldSoapOut">
<wsdl:part name="parameters" element="tns:HelloWorldResponse" />
</wsdl:message>
<wsdl:message name="NoReturnValueSoapIn">
<wsdl:part name="parameters" element="tns:NoReturnValue" />
</wsdl:message>
<wsdl:message name="NoReturnValueSoapOut">
<wsdl:part name="parameters" element="tns:NoReturnValueResponse" />
</wsdl:message>
<wsdl:message name="NoParaValueSoapIn">
<wsdl:part name="parameters" element="tns:NoParaValue" />
</wsdl:message>
<wsdl:message name="NoParaValueSoapOut">
<wsdl:part name="parameters" element="tns:NoParaValueResponse" />
</wsdl:message>
<wsdl:portType name="WebSerSoap">
<wsdl:operation name="HelloWorld">
<wsdl:input message="tns:HelloWorldSoapIn" />
<wsdl:output message="tns:HelloWorldSoapOut" />
</wsdl:operation>
<wsdl:operation name="NoReturnValue">
<wsdl:input message="tns:NoReturnValueSoapIn" />
<wsdl:output message="tns:NoReturnValueSoapOut" />
</wsdl:operation>
<wsdl:operation name="NoParaValue">
<wsdl:input message="tns:NoParaValueSoapIn" />
<wsdl:output message="tns:NoParaValueSoapOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="WebSerSoap" type="tns:WebSerSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="HelloWorld">
<soap:operation soapAction="ChineShine/HelloWorld" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="NoReturnValue">
<soap:operation soapAction="ChineShine/NoReturnValue" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="NoParaValue">
<soap:operation soapAction="ChineShine/NoParaValue" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="WebSerSoap12" type="tns:WebSerSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="HelloWorld">
<soap12:operation soapAction="ChineShine/HelloWorld" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="NoReturnValue">
<soap12:operation soapAction="ChineShine/NoReturnValue" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="NoParaValue">
<soap12:operation soapAction="ChineShine/NoParaValue" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="WebSer">
<wsdl:port name="WebSerSoap" binding="tns:WebSerSoap">
<soap:address location="http://172.168.0.40:8086/WebSer.asmx" />
</wsdl:port>
<wsdl:port name="WebSerSoap12" binding="tns:WebSerSoap12">
<soap12:address location="http://172.168.0.40:8086/WebSer.asmx" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
折叠后查看

注意:WSDL元素[1]基于XML语法描述了与服务进行交互的基本元素:
Type(消息类型):数据类型定义的容器,它使用某种类型系统(如XSD)。
Message(消息):通信数据的抽象类型化定义,它由一个或者多个part组成。
Part:消息参数
Operation(操作):对服务所支持的操作进行抽象描述,WSDL定义了四种操作: 1.单向(one-way):端点接受信息;2.请求-响应(request-response):端点接受消息,然后发送相关消息;3.要求-响应(solicit-response):端点发送消息,然后接受相关消息;4.通知(notification[2]):端点发送消息。
Port Type (端口类型):特定端口类型的具体协议和数据格式规范。
Binding:特定端口类型的具体协议和数据格式规范
Port:定义为绑定和网络地址组合的单个端点。
Service:相关端口的集合,包括其关联的接口、操作、消息等。
2.1 targerNamespasce
主要声明的是:本服务使用的命名空间 ,默认是:http://tempuri.org/
(打开一看,跑到bing去了,呵呵),可以自定义使用,如本文定义了:ChineShine
2.2 wsdl:types
主要是:服务接口里面的:方法名称,参数,返回值介绍
2.3 wsdl:Message、wsdl:portType (参看以上注意)
2.4 wsdl:Binding
可以使用的协议访问,如示例中提示使用的soap(即soap1.1),soap12(即soap1.2)
2.5 wsdl:service
主要是:各种方式服务的接口地址
综述:其实在调用别人web服务的时候,只要有web服务地址,即可能够使用,对方的服务,要详细正确使用还需服务开发者,提供详细调用文档。
三、客户端服务引用(这里才是重点啊)
客户端引用主要包含:项目中引用服务地址,普通引用(主要指VS中的“添加服务引用”)
| 名称 | 使用场景 | 优缺点 | |
| 普通引用 | 项目建立初期 | 初期建立,方便快捷,易于使用 | |
| 使用代理类 | 完善的项目,使用中的项目,
需求变更的项目,当然初期的也可以 |
需要自己手工编写代码,
对于成熟使用的项目扩展性好 |
|
| 代码引用 | post |
完善的项目,使用中的项目, 需求变更的项目,当然初期的也可以 |
需要自己手工编写代码, 对于成熟使用的项目扩展性好 |
| get | |||
| soap1.1 | |||
| soap1.2 |
3.1 普通引用
在需要引用的VS项目中,引用→添加服务引用→添加服务地址“http://172.168.0.40:8086/WebSer.asmx”,
编写基本代码即可使用
TestServiceReference.WebSerSoapClient wc = new TestServiceReference.WebSerSoapClient();//初始化web服务客户端对象
string ss=wc.HelloWorld("你好");//调用web服务的,接口方法
说明:这种方法适用于VS操作,其他语言及IDE未测试。优点方便快捷,简单易于使用。
3.2 代码引用
这里以soap1.1 为例,post,get比较简单,soap1.2 与soap1.1类似,讲述soap1.1后会添加全部代码
打开其中一个接口,参看

注:前提条件,根据接口的wsdl,以及开发商提供的文档可以查看到:接口的地址(URL)、方法名(Method)、参数列表(Paras)、命名空间等信息(tns)
编写请求代码:
//创建一个HttpWebRequest
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL);
request.Method = "POST";//请求方式
request.ContentType = "text/xml; charset=utf-8";//网络文件的类型和网页的编码
request.Headers.Add("SOAPAction", "\"" + XmlNs + (XmlNs.EndsWith("/") ? "" : "/") + MethodName + "\"");//构建soap1.1 请求头文件
request.Credentials = CredentialCache.DefaultCredentials;//获取系统凭据
request.Timeout = 10000;//请求超时时间
byte[] data = EncodeParsToSoap(Pars, XmlNs, MethodName, soapVersion);//组织发送内容,并序列化成字节流,详细参看附注代码,
request.ContentLength = data.Length;//请求数据长度
using (Stream writer = request.GetRequestStream())//请求参数
{
writer.Write(data, 0, data.Length);
writer.Close();
}
XmlDocument doc = new XmlDocument(), doc2 = new XmlDocument();
doc = ReadXmlResponse(request.GetResponse());//接收返回消息 request.GetResponse() 附注代码已修改成使用异步编程方式
这是一次请求,就完成了。详细处理,请参看详细代码
附注:详细代码(复制到程序中,直接就可以使用哦!)
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Xml;
using System.Xml.Serialization; namespace TestWS
{
public class WebServicesCodeTool
{
private System.Collections.Hashtable _xmlNamespaces = new System.Collections.Hashtable();//缓存xmlNamespace,避免重复调用GetNamespace /// <summary>
/// 需要WebService支持Post调用
/// </summary>
public System.Xml.XmlDocument QueryPostWebService(String URL, String MethodName, System.Collections.Hashtable Pars)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL + "/" + MethodName);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
SetWebRequest(request);
byte[] data = EncodePars(Pars);
WriteRequestData(request, data);
return ReadXmlResponse(request.GetResponse());//这里没有修改成异步方式,建议自行修改
} /// <summary>
/// 需要WebService支持Get调用
/// </summary>
public XmlDocument QueryGetWebService(String URL, String MethodName, Hashtable Pars)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL + "/" + MethodName + "?" + ParsToString(Pars));
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
SetWebRequest(request);
return ReadXmlResponse(request.GetResponse());
}
/// <summary>
/// 通用WebService调用(Soap),参数Pars为String类型的参数名、参数值、soap版本(如果支持1.2,使用1.2,默认填写1.1)
/// </summary>
/// <param name="URL"></param>
/// <param name="MethodName"></param>
/// <param name="Pars"></param>
/// <param name="soapVersion"></param>
/// <returns></returns>
public XmlDocument QuerySoapWebService(String URL, String MethodName, Hashtable Pars, string soapVersion)
{
if (_xmlNamespaces.ContainsKey(URL))
{
return QuerySoapWebService(URL, MethodName, Pars, _xmlNamespaces[URL].ToString(), soapVersion);
}
else
{
return QuerySoapWebService(URL, MethodName, Pars, GetNamespace(URL), soapVersion);
}
}
XmlDocument doc = null;
private XmlDocument QuerySoapWebService(String URL, String MethodName, Hashtable Pars, string XmlNs, string soapVersion)
{
_xmlNamespaces[URL] = XmlNs;//加入缓存,提高效率
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL);
request.Method = "POST"; if (soapVersion == "1.2")
{
request.ContentType = "application/soap+xml;charset=utf-8";
}
else
{
request.ContentType = "text/xml; charset=utf-8";
request.Headers.Add("SOAPAction", "\"" + XmlNs + (XmlNs.EndsWith("/") ? "" : "/") + MethodName + "\"");
}
SetWebRequest(request);
byte[] data = EncodeParsToSoap(Pars, XmlNs, MethodName, soapVersion);
WriteRequestData(request, data); XmlDocument doc2 = new XmlDocument();
IAsyncResult ar = request.BeginGetResponse(AsyncCallbackGetResponse, request);//异步方式
//XmlDocument doc = new XmlDocument();
//doc = ReadXmlResponse(request.GetResponse());//原来同步方式
if (ar.IsCompleted && doc != null)
{
XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
String RetXml = "";
if (soapVersion == "1.2")
{
mgr.AddNamespace("soap12", "http://www.w3.org/2003/05/soap-envelope");
RetXml = doc.SelectSingleNode("//soap12:Body/*/*", mgr).InnerXml;
}
else
{
mgr.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
RetXml = doc.SelectSingleNode("//soap:Body/*/*", mgr).InnerXml;
}
doc2.LoadXml("<root>" + RetXml + "</root>");
AddDelaration(doc2); }
return doc2;
} private void AsyncCallbackGetResponse(IAsyncResult ar)
{
WebRequest request = ar.AsyncState as WebRequest;
var response = request.EndGetResponse(ar);
Stream stream = response.GetResponseStream();
using (StreamReader reader = new StreamReader(stream))
{
string content = reader.ReadToEnd();
if (!string.IsNullOrEmpty(content))
{
doc = new XmlDocument();
doc.LoadXml(content);
}
}
} /// <summary>
/// 第一次执行获取要访问的命名空间
/// </summary>
/// <param name="URL"></param>
/// <returns></returns>
private string GetNamespace(String URL)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL + "?WSDL");
SetWebRequest(request);
WebResponse response = request.GetResponse();
XmlDocument doc = null;
using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
doc = new XmlDocument();
doc.LoadXml(sr.ReadToEnd());
sr.Close();
}
return doc != null ? doc.SelectSingleNode("//@targetNamespace").Value : "http://tempuri.org/";
} private byte[] EncodeParsToSoap(Hashtable Pars, String XmlNs, String MethodName, string soapVersion)
{
XmlDocument doc = new XmlDocument();
XmlElement soapBody = null;
if (soapVersion == "1.2")
{
doc.LoadXml("<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\"></soap12:Envelope>");
AddDelaration(doc);
soapBody = doc.CreateElement("soap12", "Body", "http://www.w3.org/2003/05/soap-envelope");
}
else
{
doc.LoadXml("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"></soap:Envelope>");
AddDelaration(doc);
soapBody = doc.CreateElement("soap", "Body", "http://schemas.xmlsoap.org/soap/envelope/");
}
XmlElement soapMethod = doc.CreateElement(MethodName);
soapMethod.SetAttribute("xmlns", XmlNs);
foreach (string k in Pars.Keys)
{
XmlElement soapPar = doc.CreateElement(k);
soapPar.InnerXml = ObjectToSoapXml(Pars[k]);
soapMethod.AppendChild(soapPar);
}
soapBody.AppendChild(soapMethod);
doc.DocumentElement.AppendChild(soapBody);
return Encoding.UTF8.GetBytes(doc.OuterXml);
} private string ObjectToSoapXml(object o)
{
XmlSerializer mySerializer = new XmlSerializer(o.GetType());
MemoryStream ms = new MemoryStream();
mySerializer.Serialize(ms, o);
XmlDocument doc = new XmlDocument();
doc.LoadXml(Encoding.UTF8.GetString(ms.ToArray()));
if (doc.DocumentElement != null)
{
return doc.DocumentElement.InnerXml;
}
else
{
return o.ToString();
}
} private void SetWebRequest(HttpWebRequest request)
{
request.Credentials = CredentialCache.DefaultCredentials;
request.Timeout = ;
} private void WriteRequestData(HttpWebRequest request, byte[] data)
{
request.ContentLength = data.Length;
using (Stream writer = request.GetRequestStream())
{
writer.Write(data, , data.Length);
writer.Close();
}
} private byte[] EncodePars(Hashtable Pars)
{
return Encoding.UTF8.GetBytes(ParsToString(Pars));
} private String ParsToString(Hashtable Pars)
{
StringBuilder sb = new StringBuilder();
foreach (string k in Pars.Keys)
{
if (sb.Length > )
{
sb.Append("&");
}
sb.Append(HttpUtility.UrlEncode(k) + "=" + HttpUtility.UrlEncode(Pars[k].ToString()));
}
return sb.ToString();
} private XmlDocument ReadXmlResponse(WebResponse response)
{
String retXml = "";
using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
retXml = sr.ReadToEnd();
sr.Close();
}
XmlDocument doc = new XmlDocument();
if (!string.IsNullOrEmpty(retXml)) { doc.LoadXml(retXml); }
return doc;
} private void AddDelaration(XmlDocument doc)
{
XmlDeclaration decl = doc.CreateXmlDeclaration("1.0", "utf-8", null);
doc.InsertBefore(decl, doc.DocumentElement);
} }
}
项目中的调用:
WebServicesTool ws = new WebServicesTool();
Hashtable paras = new Hashtable();
paras.Add("ss", "你好");
XmlDocument docPost = ws.QueryPostWebService("http://172.168.0.40:8086/WebSer.asmx", "HelloWorld", paras);
XmlDocument docSoap = ws.QuerySoapWebService("http://172.168.0.40:8086/WebSer.asmx", "HelloWorld", paras, "1.2");
context.Response.Write(docPost.OuterXml);
context.Response.Write(docSoap.OuterXml);
3.3 使用wsdl代理类
①、查看webservice服务,访问Service Document,即这里的wsdl文件,
②、将查看的wsdl文件保存。
③、本机使用VS自带的“VS2013 开发人员命令提示”。点击打开
④、wsdl 文件路径,即可生成代理类,调用代理类即可访问不同程序编写的webservice服务
四、心得
4.1 使用代码方式,使得成熟稳定的项目,易于扩展。
4.2 不论何种语言,只要读懂wsdl及接口开发商提供文档即可,调用web接口。
4.3 一些关于soap1.2 的简介http://blog.csdn.net/xiaojianpitt/article/details/5258254
更多的soap介绍,可以查看:http://www.ibm.com/developerworks/cn/xml/x-sisoap/
Webservices-2.C#创建web服务,及引用访问、代码访问的更多相关文章
- 手把手教你在.NET中创建Web服务
最近发现在.NET平台下使用Web服务还是很简单的.下面举个在.NET平台下创建Web服务的简单例子.首先用Visul Studio .Net创建一个C# 项目Asp.Net Web服务程序,源代码如 ...
- 基于Socket创建Web服务
基于Socket创建Web服务 为什么要使用Socket呢,我们来看下图
- ASP.NET---如何使用web api创建web服务
1 首先创建asp.net web空项目,并且创建模拟数据,我在工程下面创建了一个Models文件夹,在文件夹Nodels下面创建类Product和Repository 具体如下: [Serializ ...
- http-server让你在任何目录下都可以创建web服务
在做前端页面开发,或者预览时,如果借助于Apache.Tomcat.nginx等预览页面,每次需要将所需预览的页面移动到对应的文件夹下,且还需要考虑是否删除相关目录原有的文件,显然比较麻烦. 那么有没 ...
- Web Service 实例基于Socket创建Web服务
ServerSocket服务器端代码如下: public static void main(String[] args) throws IOException { // 1:建立服务器端的tcp so ...
- 使用BPEL创建Web服务组合
http://www.cnblogs.com/ahhuiyang/archive/2012/12/18/2824131.html 为简单起见,本例的Web服务组合只调用一个Web Service AP ...
- asyncio创建协程解析——分析廖雪峰的Python教程之创建WEB服务(转)
第一步,搭建开发环境 所需第三方库: aiohttp,异步 Web 开发框架:jinja2,前端模板引擎:aiomysql,异步 mysql 数据库驱动 所需内置库: logging,系统日志:asy ...
- 使用记事本创建Web服务(WebService)
学习就要从最简单最直观的地方入手. 1)打开记事本,添加如下代码: <%@ WebService Language="C#" Class="myFirstWebSe ...
- Golang: 创建Web服务
使用 Go 语言,我们可以轻松创建出 Web 服务,这一点比 Node.js 还要简单,今天就来总结一下 Go 语言中 Web 服务的创建方式. 首先,我们需要引入 net/http 这个包来处理 H ...
随机推荐
- Validate XML using a XSD (XML Schema)
Consider this XML file howto.xml : <?xml version="1.0" encoding="ISO-8859-1"? ...
- kafka offset-check工具失效的问题
转载请注明原创地址http://www.cnblogs.com/dongxiao-yang/p/5414077.html 由于平时业务预警等需求,针对现在公司的kafka系统部署了几套监控系统,包括调 ...
- jQuery自定义多选下拉框
项目中需要自定义一个下拉框多选插件,业务问题还是自己实现比较好 通过$.fn 向jQuery添加新的方法 下拉数据通过参数传递进去,通过调用该插件时接收,选择后的确定与取消事件采用事件传递方式 代码如 ...
- RPM制作
http://blog.csdn.net/justlinux2010/article/details/9905425
- .Net4.0如何实现.NET4.5中的Task.Run及Task.Delay方法
前言 .NET4.0下是没有Task.Run及Task.Delay方法的,而.NET4.5已经实现,对于还在使用.NET4.0的同学来说,如何在.NET4.0下实现这两个方法呢? 在.NET4.0下, ...
- TCP/IP协议原理与应用笔记13:底层网络技术之传输介质
1. 有线介质----导线管(导向媒体) • 双绞线 Twisted-pair cable • 同轴电缆 Coaxial cable 金属铜导线,电流 • 光纤 Fiber-optic cable ...
- windows10UWP:如何在xaml中设置控件为 public ?
windows10UWP中,由于使用页面导航,操作在不同一个页面的控件需求经常遇到. 如果要对另一个page里面的控件进行操作,那么这个控件必须设置为 public .在 xaml 设置控件的方法是: ...
- Stream类
为什么需要 Stream Stream 作为 Java 8 的一大亮点,它与 java.io 包里的 InputStream 和 OutputStream 是完全不同的概念.它也不同于 StAX 对 ...
- poj1742 Coins(多重背包+单调队列优化)
/* 这题卡常数.... 二进制优化或者单调队列会被卡 必须+上个特判才能过QAQ 单调队列维护之前的钱数有几个能拼出来的 循环的时候以钱数为步长 如果队列超过c[i]就说明队头的不能再用了 拿出来 ...
- JS(一)
额, 写了一堆, 待机win8崩溃, 重启之后只剩光秃秃的界面, 以后再填吧, 下次一定要一口气把博客写完,中间不能放下干其他事. 1.对象,以及对象与方法联合: var bob = new Obje ...