代码改变世界

调用具体webservice方法时时报错误:请求因 HTTP 状态 503 失败: Service Temporarily Unavailable

2014-08-12 10:19  悠悠鑫宝  阅读(9597)  评论(0编辑  收藏  举报

添加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 通过映射端口发布到外网,调用报错解决 

环境:

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?

image

在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引用,然后调用。