2012-02-24 109 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