Exchange2010 二次开发 调用EWS 报http 500内部服务错误
对于500错误,只能去该exchange服务器上查看windows的应用程序日志:
详细信息如下
System.ServiceModel.ServiceHostingEnvironment+HostingManager/48948582
System.ServiceModel.ServiceActivationException: 由于编译过程中出现异常,无法**服务“/EWS/exchange.asmx”。异常消息为: 此集合已经包含方案 http 的地址。此集合中每个方案中最多只能包含一个地址。参数名: item。 ---> System.ArgumentException: 此集合已经包含方案 http 的地址。此集合中每个方案中最多只能包含一个地址。参数名: item 在 System.ServiceModel.UriSchemeKeyedCollection.InsertItem(Int32 index, Uri item) 在 System.Collections.Generic.SynchronizedCollection`1.Add(T item) 在 System.ServiceModel.UriSchemeKeyedCollection..ctor(Uri[] addresses) 在 System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses) 在 System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(Type serviceType, Uri[] baseAddresses) 在 System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) 在 System.ServiceModel.ServiceHostingEnvironment.HostingManager.CreateService(String normalizedVirtualPath) 在 System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(String normalizedVirtualPath) 在 System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) --- 内部异常堆栈跟踪的结尾 --- 在 System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) 在 System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath)
w3wp
7052
关键信息为:此集合已经包含方案 http 的地址。此集合中每个方案中最多只能包含一个地址。参数名: item
原因是exchange2010 追加了WCF最为中间处理服务,访问EWS下的MRSProxy.svc这个wcf服务同样提示该错误
可以确定是WCF的问题,经过相关查询,使用如下解决方案
WCF 错误:此集合已经包含方案 http 的地址。此集合中每个方案中最多只能包含一个地址。
解决方案:
在webservice的 web.config中system.serviceModel 标签下添加如下标签项。prefix内的值根据部署的网站ip、主机名、端口号会有所不同
<system.serviceModel>
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://mail.thtoa.gov.cn"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
</system.serviceModel>
web.config修改完成之后保存,重启IIS。问题解决。