我正在尝试按下按钮时调用GetSuggestedCategories API调用。这很好。
接下来,我试图在后续按下按钮上调用GeteBayDetails API调用。这是我收到以下错误的地方:
{"java.lang.ClassCastException: com.ebay.domain.apisoap.pres.service.hosting.soap.basecomponents.GetSuggestedCategoriesResponseType incompatible with com.ebay.domain.apisoap.pres.service.hosting.soap.basecomponents.GeteBayDetailsResponseType"}
令我迷惑的是,无论我先调用哪种方法,我都可以继续无误地拨打电话。我不能在没有错误的情况下调用下一个方法。
每个方法都包含其appID,devID,certID,authToken,endpoint,callname,serviceRequest等,因此难以确定调用GeteBayDetails请求的原因是,当我没有使用时,它与GetRequestedCategories调用的引用不兼容参考它。
以下是我对GetSuggestedCategories的方法调用:
Public Function GetSuggestedCategories(keywords As String, PostingStore As String) As Dictionary(Of String, String)
appId = "My ID"
devId = "My ID"
certId = "My ID"
store1Auth = "My ID"
store2Auth = "My ID"
endpoint = "https://api.ebay.com/wsapi"
Dim returnCategories As New Dictionary(Of String, String)
Dim callName As String = "GetSuggestedCategories"
Dim siteId As String = SiteCodeType.US
Dim version As String = "1031"
'build the request URL
Dim requestURL As String = endpoint +
"?callname=" + callName +
"&siteid=" + siteId +
"&appid=" + appId +
"&version=" + version +
"&routing=default"
'Create the service
Dim service As eBayAPIInterfaceClient = New eBayAPIInterfaceClient("eBayAPI", requestURL)
Dim requesterCredentials As CustomSecurityHeaderType = New CustomSecurityHeaderType
requesterCredentials.eBayAuthToken = If(PostingStore = "Store 1", store1Auth, If(PostingStore = "Store 2", store2Auth, Nothing))
If requesterCredentials.eBayAuthToken = Nothing Then
service.Close()
service = Nothing
requesterCredentials = Nothing
returnCategories.Add("3", "Amazon Auth Token Not Recognized or Store not set up.")
Return returnCategories
End If
requesterCredentials.Credentials = New UserIdPasswordType
requesterCredentials.Credentials.AppId = appId
requesterCredentials.Credentials.DevId = devId
requesterCredentials.Credentials.AuthCert = certId
'Make the call to AddFixedPriceItem
Dim request As eBayWSDL.GetSuggestedCategoriesRequestType = New GetSuggestedCategoriesRequestType
request.Version = version
request.Query = keywords
Dim asyncResponse As GetSuggestedCategoriesResponse
Try
'asyncResponse = Await service.GetSuggestedCategoriesAsync(requesterCredentials, request)
'Dim response As GetSuggestedCategoriesResponseType = asyncResponse.GetSuggestedCategoriesResponse1
Dim response As GetSuggestedCategoriesResponseType = service.GetSuggestedCategories(requesterCredentials, request)
If response.Ack <> AckCodeType.Failure Then
If Not response.SuggestedCategoryArray Is Nothing Then
returnCategories.Add("0", "Complete with no errors.")
For Each cID In response.SuggestedCategoryArray.SuggestedCategory
returnCategories.Add(cID.Category.CategoryName, cID.Category.CategoryID)
Next
ElseIf Not response.Any Is Nothing Then
returnCategories.Add("0", "Complete with no errors.")
For Each xmlResponse In response.Any
Dim xmlConverter As New XmlDocumentConverter(xmlResponse)
Dim allCategories As Dictionary(Of String, String) = xmlConverter.ConvertToStringDictionary("CategoryID", "CategoryName", "Category")
For Each cat In allCategories
returnCategories.Add(cat.Key, cat.Value)
Next
Next
Else
returnCategories.Add("2", "No Suggested Categories Were Found.")
End If
Else
returnCategories.Add("1", "Errors returned.")
Dim err As ErrorType
For Each err In response.Errors
returnCategories.Add(err.ErrorCode, err.ShortMessage)
Next err
End If
Catch ex As Exception
Finally
service.Close()
service = Nothing
requesterCredentials = Nothing
request = Nothing
asyncResponse = Nothing
End Try
Return returnCategories
这是我调用GeteBayDetails的方法:
Public Function GetShippingServiceDetails(PostingStore As String) As Dictionary(Of String, String)
appId = "My ID"
devId = "My ID"
certId = "My ID"
store1Auth = "My ID"
store2Auth = "My ID"
endpoint = "https://api.ebay.com/wsapi"
Dim returnExcludes As New Dictionary(Of String, String)
Dim callName As String = "GeteBayDetails"
Dim siteId As String = SiteCodeType.US
Dim version As String = "1031"
'build the request URL
Dim requestURL As String = endpoint +
"?callname=" + callName +
"&siteid=" + siteId +
"&appid=" + appId +
"&version=" + version +
"&routing=default"
'Create the service
Dim service As eBayAPIInterfaceClient = New eBayAPIInterfaceClient("eBayAPI", requestURL)
Dim requesterCredentials As CustomSecurityHeaderType = New CustomSecurityHeaderType
Try
requesterCredentials.eBayAuthToken = If(PostingStore = "Store 1", store1Auth, If(PostingStore = "Store 2", store2Auth, Nothing))
If requesterCredentials.eBayAuthToken Is Nothing Then
Throw New NullReferenceException("An auth token was not found for the selected store")
End If
Catch ex As Exception
service.Close()
service = Nothing
requesterCredentials = Nothing
returnExcludes.Add("3", ex.Message)
Return returnExcludes
End Try
requesterCredentials.Credentials = New UserIdPasswordType
requesterCredentials.Credentials.AppId = appId
requesterCredentials.Credentials.DevId = devId
requesterCredentials.Credentials.AuthCert = certId
'Make the call to AddFixedPriceItem
Dim request As eBayWSDL.GeteBayDetailsRequestType = New GeteBayDetailsRequestType
request.Version = version
Dim detailNameList As New List(Of DetailNameCodeType)
detailNameList.Add(DetailNameCodeType.ShippingServiceDetails)
request.DetailName = detailNameList.ToArray
'Dim asyncResponse As GeteBayDetailsResponse
Try
'asyncResponse = Await service.GeteBayDetailsAsync(requesterCredentials, request)
'Dim response As GeteBayDetailsResponseType = asyncResponse.GeteBayDetailsResponse1
Dim response As GeteBayDetailsResponseType = service.GeteBayDetails(requesterCredentials, request)
If response.Ack <> AckCodeType.Failure Then
If Not response.ExcludeShippingLocationDetails Is Nothing Then
returnExcludes.Add("0", "Complete with no errors.")
For Each cID In response.ShippingServiceDetails
If cID.ValidForSellingFlow = True Then
returnExcludes.Add(cID.ServiceType.ToString, cID.Description)
End If
Next
ElseIf Not response.Any Is Nothing Then
returnExcludes.Add("0", "Complete with no errors.")
For Each xmlResponse In response.Any
Dim xmlConverter As New XmlDocumentConverter(xmlResponse)
Dim allCategories As Dictionary(Of String, String) = xmlConverter.ConvertToStringDictionary("ServiceType", "Description", "False", "")
For Each cat In allCategories
returnExcludes.Add(cat.Key, cat.Value)
Next
Next
Else
returnExcludes.Add("2", "No Suggested Locations Were Found.")
End If
Else
returnExcludes.Add("1", "Errors returned.")
Dim err As ErrorType
For Each err In response.Errors
returnExcludes.Add(err.ErrorCode, err.ShortMessage)
Next err
End If
Catch ex As Exception
Finally
service.Close()
service = Nothing
requesterCredentials = Nothing
request = Nothing
'asyncResponse = Nothing
End Try
Return returnExcludes
End Function