2012-02-24 35 views
0

this link获取TripPriceService.wsdl通过从保存在本地文件夹中的wsdl文件中提供wsdl,将服务引用(ServiceReference1)添加到Windows应用程序。我的问题有两部分:在我的soapclient中捕获异常

1)以下故障消息是否为根据wsdl(TripPriceServiceException)的有效soap故障?

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:trip="http://trip.price.service"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <soapenv:Fault> 
     <faultcode>soapenv:client</faultcode> 
     <faultstring>error</faultstring> 
     <detail> 
      <trip:TripPriceServiceException/> 
     </detail> 
     </soapenv:Fault> 
    </soapenv:Body> 
</soapenv:Envelope> 

2)现在如何处理和捕获细节标签,当响应是一个soap:fault?

Imports windowsapp1.ServiceReference1 
Public Class Form1 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
     Dim obj As New ServiceReference1.TripPriceServiceFacadeClient 
     Dim abc As New ServiceReference1.trip 
     Dim a As Single 
     Dim d As ServiceReference1.TripPriceServiceException 
     a = obj.getTripPrice(abc) 
    End Sub 
End Class 

行obj.getTripPrice调用服务。但是,如果响应是一个SOAP错误(TripPriceServiceException类型),它会抛出异常吗?如何处理这种情况,我们是否需要使用ServiceReference1.TripPriceServiceException?我只是用这个wsdl来解释我目前的情况。我们需要在我们的web服务客户端处理这些错误。

回答

0

也许我不明白你的问题。为什么不使用Try/Catch/End Try块并捕获TripPriceServiceException?

+0

嗨约翰,是肥皂故障xml有效的TrpPriceServiceExcetion。为什么我这么问是因为,任何有效的XML都可能出现在肥皂错误的详细标签中。然而,对于TripPriceServiceException类型,只有旅行:TripPriceServiceException元素可以在详细标签下(据我undertsnad) – Suresh 2012-02-25 04:14:52

+1

它看起来有效。你是对的,只有那个元素(没有内容)才会出现这个错误。它应该转化为一个'FaultException ',你可以捕获它。 – 2012-02-25 04:55:13

+0

嗨,约翰。在我们为了测试我们的web服务而开发的示例web服务客户端中,我得到了“消息=服务器提交了违反协议的情况。部分= ResponseHeader Detail = CR后面必须跟LF”这个错误。我知道,如果我们添加useUnsafeHeaderParsing =“true”,它会去。但是,我们是服务提供商,不知道为什么客户端出现此错误。我使用Xslt,xml转换来生成soap故障。响应是从数据电源设备引发的。 – Suresh 2012-02-27 07:25:54