添加web引用會在相應項目的app.cofig文件中產生如下代碼:
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="BS.EAP.BizMgt.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
………………
<BS.EAP.BizMgt.Properties.Settings>
<setting name="BS_EAP_BizMgt_IPersonCard_PetroChina" serializeAs="String">
<value>http://10.27.213.172:8080/PetroChinaService/PetroChina</value>
</setting>
<setting name="BS_EAP_BizMgt_GetVisitService_ReportSSO" serializeAs="String">
<value>http://10.88.248.111:88/dm/cxf-services/ReportSSO</value>
</setting>
</BS.EAP.BizMgt.Properties.Settings>
</applicationSettings>
</configuration>
紅色字部分是所引用web服務地址:http://10.88.248.111/dm/cxf-services/ReportSSO
要手動增加上端口88問題解決
以下內容應用自:http://www.cnblogs.com/BruceLee521/archive/2012/03/28/2420776.html
環境:
Webservice部署到內網機器,地址:http://aaa.bbb.ccc.ddd/xkzjk/LicensesService.asmx
通過端口影射到外網地址:http://eee.fff.ggg.hhh:88/xkzjk/LicensesService.asmx
同事碰到的第一個問題:
在Visual Studio中引用Webservice報如下錯誤:
在Visual Studio 2008下報如下錯誤:
Unable to download following files from.
http://eee.fff.ggg.hhh:88/xkzjk/LicensesService.asmx?wsdl
Do you want to skip these files and continue?
在Visual Studio 2010報如下錯誤:
An error(Details) occurred while attempting to find services at ‘http://eee.fff.ggg.hhh:88/xkzjk/LicensesService.asmx’
元數據包含無法解析的引用:“http://eee.fff.ggg.hhh:88/xkzjk/LicensesService.asmx?wsdl”。
下載“http://eee.fff.ggg.hhh:88/xkzjk/LicensesService.asmx?wsdl”時出錯。
請求因 HTTP 狀態 503 失敗: Service Temporarily Unavailable。
元數據包含無法解析的引用:“http://eee.fff.ggg.hhh:88/xkzjk/LicensesService.asmx?wsdl”。
元數據包含無法解析的引用:“http://eee.fff.ggg.hhh:88/xkzjk/LicensesService.asmx?wsdl”。
If the service is defined in the current solution, try building the solution and adding the service reference again.
原因:
開發人員對Webservice不懂,WSDL不知道是干什么的,引用的地址少了?wsdl,第一個問題解決。
同事碰到的第二個問題:
調用具體webservice方法時時報如下錯誤
請求因 HTTP 狀態 503 失敗: Service Temporarily Unavailable。
說明: 執行當前 Web 請求期間,出現未經處理的異常。請檢查堆棧跟蹤信息,以了解有關該錯誤以及代碼中導致錯誤的出處的詳細信息。
異常詳細信息: System.Net.WebException: 請求因 HTTP 狀態 503 失敗: Service Temporarily Unavailable。
分析:
具體去看異常內部信息:
ResponseUri={http://eee.fff.ggg.hhh/xkzjk/LicensesService.asmx},開始沒仔細看,后來找了很久,發現少了外網映射的端口88。
原因:
在Visual Studio 2008中引用Webservice時,在Web.config中自動增加如下節
<applicationSettings>
<Test.Web.Properties.Settings>
<setting name="Test_Web_LicService_LicensesService" serializeAs="String">
<value>http://eee.fff.ggg.hhh/xkzjk/LicensesService.asmx</value>
</setting>
</Test.Web.Properties.Settings>
</applicationSettings>
在工程的Settings.settings文件中增加了App的設置,代理類會使用該設置的變量。
在Visual Studio 2010中引用Webservice時,在Web.config中自動增加如下節
endpoint address="http://eee.fff.ggg.hhh/xkzjk/LicensesService.asmx"
binding="basicHttpBinding" bindingConfiguration="LicensesServiceSoap"
contract="ServiceReference1.LicensesServiceSoap" name="LicensesServiceSoap" />
定義了Webservice的一些基本信息。
請注意Visual Studio都把端口去掉了。手動在Web.config里增加上88端口問題解決。
總結:第一個問題是因為對Webservice的原理不明白。第二個對Visual Studio引用Webservice的原理不清楚,只會用,現在很多人對Webservice的一些基本理論知識都不明白,就是上來就用Visual Studio引用,然后調用。