Winfx必须运行在WinXP sp2之后的OS
【IT168 技术新闻】
为什么 Winfx 必须运行在windows xp sp2 和 windows 2003 以及之后的OS ?
Winfx 目前已经到了Beta2的版本,主要包含WCF,WF,WPF 三部分。如果您要开发一些SOA 应用的话,WCF是一个很好的平台。他一方面很好的支持WS-*, 同时对于.NET 平台下的SOA又有自己的支持。
具体安装步骤,可以参考:
http://msdn.microsoft.com/windowsvista/downloads/products/getthebeta/
也可以参我我以前写的一片文章 SOA: msmq, WCF(Indigo), HelloWorld
http://montaque.cnblogs.com/archive/2006/01/10/314684.html
这时候,Runtime 会告诉你
Supported Operating Systems: Longhorn (Windows Code Name) ; Windows Server 2003 Service Pack 1; Windows XP Service Pack 2
今天在测试程序的时候,好似找到了一个理由,嘿嘿。听我慢慢道来。
对于一个Service,微软给他定义了一个ABC Address,Binding,Contract
所以WCF中以下配置很常见。描述了ABC
<services> <service type="Server.DerivativesCalculator,Server" behaviorConfiguration=
"DerivativesCalculatorServiceBehavior"> <endpoint address="http://localhost:8000/Derivatives/Calculator" binding="wsDualHttpBinding" bindingConfiguration="B2BIdentification" contract="Server.IDerivativesCalculator,Server" /> </service> </services>
这时候,Console Host运行这个程序的时候。改程序就可以处理client通过http过来的请求调用。这时候问题就来了,WCF 用什么来处理http请求呢?
我们知道Remoting 的时候,微软用的一些native的http处理方式,当然这个方式就跟平台无关了。
当你用IE去请求一个WSDL的时候,他的响应,嘿嘿。可以看到他的"Server"
HTTP/1.1 200 OK
Content-Type: text/xml
Server: MS .NET Remoting, MS .NET CLR 2.0.50727.42
Content-Length: 3057
而 WCF 的时候,你同样的方式去请求WSDL的话。他的http头
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Content-Type: text/html
Server: Microsoft-HTTPAPI
Date: Mon, 29 May 2006 04:09:24 GM
呵呵,这个头事实上说明他用了.Net 2.0 的类HttpListner 来做一个bulit-in web server ,而这个HttpListner 是xp sp2 跟 2003 才支持的。
这个帮助也说了该类仅在运行 Windows XP SP2 或 Windows Server 2003 操作系统的计算机上可用。如果尝试在运行更早版本操作系统的计算机上创建 HttpListener 对象,构造函数将引发 PlatformNotSupportedException 异常。
为什么呢,他用了一个low level http协议栈 http.sys, 而这个http.sys 是后面两个平台才有的。
关于httpListner 和 http.sys 。请参考一下两个link
在没有 IIS 的条件下运行 ASMX
http://www.microsoft.com/china/MSDN/library/WebServices/WebServices/ServiceStation.mspx?mfr=true
当然,你可以写一个简单的处理web请求的mini web server,贴一段代码
using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Threading; using System.Net; namespace HttpListnerDemo { class Program { static void Main(string[] args) { System.Net.HttpListener listner = new System.Net.HttpListener(); listner.Prefixes.Add("http://+:8000/"); listner.Start(); while (true) { System.Net.HttpListenerContext context = listner.GetContext(); System.Threading.ThreadPool.QueueUserWorkItem( new System.Threading.WaitCallback(ProcessContext), context); } } public static void ProcessContext(object objContext) { try { HttpListenerContext context = objContext as HttpListenerContext; Console.WriteLine(context.Request.Url); context.Response.ContentType = "text/html"; StreamWriter writer = new StreamWriter(context.Response.OutputStream); writer.WriteLine(string.Format("<h1>{0}</h1><br>{1}",
context.Request.Url,DateTime.Now.ToString())) ; writer.Flush(); context.Response.Close(); } catch (System.Net.HttpListenerException exception) { Console.WriteLine(exception.Message); } } } }