WCF的配置文件的baseAddress的真正含义

来源:互联网 发布:中国防火墙 知乎 编辑:程序博客网 时间:2024/05/16 14:09

WCF的配置太多,难度比asmx百倍以上,asmx通常都不需要配置,真正的hassle free,不过微软对这么好的东东居然停止维护,不知道哪根筋出错了。

近来产品服务器更新,自动更新了.net framework 3.5 SP,asp.NET4不能和ASP.net2混着用,真的是把我急坏了,好几个小时才弄好,那时压力真的很大,服务停了这么长时间。

感叹WCF太恐怖了,配置太难了。

首先不知为何WCF HTTP activation组件被自动卸载,症状是svc后缀不能识别,

the requested content appears to be script and will not be served by the static file handler

在program 和feature程序里把WCF HTTP activation feature选上后,就行了,

后来又发现即使WCF HTTP activation feature安装了 ,但是还是出现同样的问题。

google 一下发现

The error occurred since the Service Model is not registered in my machine,

which handles the WCF service request. However, you can install it manually from the command line:

.NET 3.0

Location: C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation
Command Line: ServiceModelReg.exe –i

然后这个错误就消失了。

然后又出现baseAddress的问题,这个和web.config和IIS bingding密切相关,但是没有看到一篇好的文章讲过baseAddress和IIS binding的关系。

如果你在。NET framework 2里面用WCF,web。confg而且iis binding里只配置了web site 和localhost或者局域网地址 ,没有申明过任何baseAddress,在发布到互联网后通常会出现wsdl里的xml schema 是无法下载的,因为schem的网址是局域网地址或者localhost,

如果你把互联网地址直接加到endpoint或者申明互联网域名为baseAddress ,会出现找不到的错误消息,为什么了?

例如你的WCF网址是 abc.com/service/file.svc, 你把endpoint的address设置为 abc.com/service/file.svc, 或者baseAddress设置为 abc.com/service,会出现找不到的错误消息。

明明写的很清楚,但是iis就是找不到。

你必须在web site 的iis binding里明确的WCF服务被部署的web site 和abc.com绑定,否则iis 是找不到abc.com/service/file.svc。

为什么很多人不把web site 和abc.com绑定了,因为如果你一个ip对应一个域名,一个web site只对应一个ip,是不需要把域名和web site 绑定,只需要把web site 和ip绑定就行。


总而言之,baseAddress必须要体现在iis binding里,这个是很多文章没有提及的。

另外iis web site 有可能有很多http 绑定,例如和localhost,局域网网址和域名绑定,但是在web.config里每个协议只能有一个baseAddress,超过一个就出错。