webservice接口修改引起的问题
现场描述:
分配系统调用了配置系统的webservice接口ConfigInterface,ConfigInterface又引用了另一个Project “ReferenceInterface”,而该Project又引用了ADS系统提供的webservice接口AdsInterface。
在分配系统调用配置系统webservice接口时,出现异常:Unable to connect to the remote server。
分析解决过程:
ConfigInterface的web.config中配置的对AdsInterface的webservice访问地址是正确的(ConfigInterface在调用服务时会动态的根据这个配置节来查找服务)。
在ReferenceInterface的web引用中将对AdsInterface的引用地址修改为http://localhost/adsinterface,更新web引用。重新编译ReferenceInterface,得到ReferenceInterface.dll。将该dll拷贝覆盖到配置系统接口目录下。
问题解决了。
具体原因是什么呢?为什么抛出的异常是这个:Unable to connect to the remote server ?
检查了下ReferenceInterface project中的web引用,发现该project引用的ADSInterface的地址是一个测试环境的地址,添加的是动态web引用。既然是动态web引用,那么在系统运行时应该会动态的根据配置文件中的url来调用服务(配置文件中的url指向的是运营环境的地址,没有问题),但是抛出的这个异常却说明ReferenceInterface一直引用的是这个测试地址提供的webservice。也就是说,动态引用没有起作用。
是怎么回事?
---------------------
今天又翻出了这个问题,自己建了个测试项目,建立类似以上的引用关系,发现webservice的动态引用没有问题。
只有配置系统存在这个问题!
于是找配置系统和这个测试项目之间的差异。
最后发现了问题所在。
在配置系统接口的web.config中发现,
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Tencent.Itil.Config.Interface.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</sectionGroup>
...
<applicationSettings>
<Tencent.Itil.Config.Interface.Properties.Settings>
<setting name="Tencent_Itil_Config_ReferenceInterface_AdsService_AdsInterface"
serializeAs="String">
<value>http://localhost/adsinterface/AdsInterface.asmx%3c/value>
</setting>
</Tencent.Itil.Config.Interface.Properties.Settings>
</applicationSettings>
而ReferenceInterface中的app.config为:
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Tencent.Itil.Config.ReferenceInterface.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="ReferenceInterface.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<Tencent.Itil.Config.ReferenceInterface.Properties.Settings>
<setting name="Tencent_Itil_Config_ReferenceInterface_AdsService_AdsInterface"
serializeAs="String">
<value>http://ip/adsinterface/AdsInterface.asmx%3c/value>
</setting>
</Tencent.Itil.Config.ReferenceInterface.Properties.Settings>
问题就在红色的部分。
将配置接口项目ConfigInterface的web.config中的Tencent.Itil.Config.Interface.Properties.Settings节点替换成Tencent.Itil.Config.ReferenceInterface.Properties.Settings。
跟踪程序后,正确取到web.config中配置的url。
问题真正得以解决!
在配置文件中节点设置不正确时,webservice只能根据默认的,也就是开始添加web引用的那个地址去找服务。在这里找到的就是那个测试环境的服务地址,配置管理系统的旧web是可以访问这个测试环境的,而新web由于访问策略控制比较严格,无法访问测试环境的地址。
这就是为什么相同的接口程序在新web上调用失败,而在旧web上调用成功的原因。
更新web引用时,由于将服务地址更新成了localhost/AdsInterface,在重新编译好拷贝到新web环境中的配置接口中后。在新web上是部署有AdsInterface的。于是调用成功了。歪打正着了。
浙公网安备 33010602011771号