我试图从.net控制台应用程序调用基于java的Web服务。我重写了GetWebResponse()方法,但它返回“响应不是格式良好的XML”。我确实有xml,只是试图摆脱这个错误。以下是代码的亮点 -
Public Class CureWebServiceHelper
Inherits FXRates2013.CureWebService.RatesWebServiceV2
Public Shared Function ConnectToWS(ByVal dataService As System.Web.Services.Protocols.WebClientProtocol) As Boolean
Try
Dim wsURL As String, wsUserId As String, wsPwd As String, wsDomain As String
With ConfigurationManager.AppSettings
wsURL = .Get("CureWebServiceURL").ToString
wsUserId = .Get("CureWebServiceUserId").ToString
wsPwd = .Get("CureWebServiceUserPwd").ToString
wsDomain = "ad-ent"
End With
dataService.Url = wsURL
Dim Creds As New System.Net.CredentialCache()
Dim netCred As New System.Net.NetworkCredential(wsUserId, wsPwd)
Creds.Add(New Uri(dataService.Url), "Basic", netCred)
dataService.Credentials = Creds 'attach password.
Return True
Catch ex As Exception
Return False
End Try
End Function
Protected Overloads Overrides Function GetWebResponse(ByVal the_webRequest As WebRequest) As WebResponse
Dim WR As WebResponse
WR = MyBase.GetWebResponse(the_webRequest)
Dim sr As New IO.StreamReader(WR.GetResponseStream)
Dim ResultStr = sr.ReadToEnd
'Populate this XML instead.
Dim ReturnXML = ResultStr
Return MyBase.GetWebResponse(the_webRequest)
End Function
End Class
在我的主要模块中 -
Sub Main()
Dim strXML As String = ""
Using webService As New CureWebServiceHelper
CureWebServiceHelper.ConnectToWS(webService)
Dim WSResponse As String
Call webService.getClosedRatesAsXml("MO_London", "12/02/2013", True, FXRates2013.CureWebService.wsRateTypeEnum.Spot, True)
End Using
End Sub
如何摆脱错误?我无法控制Web服务本身,所以我无能为力。
编辑:这是xml -
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:getClosedRatesAsXmlResponse xmlns:ns1="http://fx.wachovia.net">
<ns2:ClosedFXRatesAsXml xmlns:ns2="http://fx.wachovia.net"><OfficialClosing>
<ClosingSetName>MO_London</ClosingSetName>
<CloseDate>20131202</CloseDate>
<Status>CLOSED</Status>
<FXRate>
<NumeratorCcy>USD</NumeratorCcy>
<DenominatorCcy>SVC</DenominatorCcy>
<Tenor>SPOT</Tenor>
<Type>Spot</Type>
<Rate>8.7475</Rate>
</FXRate>
</OfficialClosing>
</ns2:ClosedFXRatesAsXml></ns1:getClosedRatesAsXmlResponse></soap:Body></soap:Envelope>