Question XML-RPC error

graham23s

Member
Joined
Feb 22, 2009
Messages
13
Programming Experience
1-3
Hi Guys,

I'm using the xml-rpc protocol to connect to a website's api:

code for button:

VB.NET:
        Dim proxy As ISapeXmlRpc = XmlRpcProxyGen.Create(Of ISapeXmlRpc)()
        'proxy.UseIntTag = True
        Dim userId As Integer = proxy.SapeLogin(formMain.txtUser.Text.Trim(), formMain.txtPass.Text.Trim())
        If (userId > 0) Then
            Try
                '// sape.get_project_sites returns array of sites IDs, 
                '// You need to declare SapeGetProjectSites as returns XmlRpcStruct()
                Dim projectSites As XmlRpcStruct() = proxy.SapeGetProjectSites(Convert.ToInt32(gbAnalysis.Text))

                For Each struct As XmlRpcStruct In projectSites
                    For Each s As String In struct.Keys
                        MessageBox.Show("Key: " + s + " Value: " + struct.Item(s).ToString())
                    Next
                Next

            Catch ex As Exception
                formMain.returnMessage("XML-RPC ERROR!" & vbCrLf & vbCrLf & ex.ToString)
            End Try
        End If

Class file.

VB.NET:
Imports CookComputing.XmlRpc

<XmlRpcUrl("http://api.site.ru/xmlrpc/")>
Public Interface ISapeXmlRpc
    Inherits IXmlRpcProxy

    <XmlRpcMethod("sape.login", Description:="Login to sape.ru")>
    Function SapeLogin(ByVal login As String, ByVal password As String, Optional ByVal md5 As Boolean = False) As Integer

    <XmlRpcMethod("sape.get_user", Description:="Get user info")>
    Function SapeGetUser() As UserInfo

    <XmlRpcMethod("sape.get_balance_locks", Description:="Get balance locks")>
    Function SapeGetRealBalance() As XmlRpcStruct

    <XmlRpcMethod("sape.get_sites", Description:="Get sites")>
    Function SapeGetSites() As XmlRpcStruct

    <XmlRpcMethod("sape.get_project", Description:="Get project")>
    Function SapeGetProject(ByVal project_id As Integer) As SapeGetProject

    <XmlRpcMethod("sape.get_project_sites", Description:="Get project sites")>
    Function SapeGetProjectSites(ByVal project_id As Integer) As XmlRpcStruct()

    <XmlRpcMethod("sape.project_update", Description:="Project update")>
    Function SapeUpdateProject(ByVal project_id As Integer, ByVal project_params As SapeProjectUpdateStruct) As Boolean

End Interface

I can see via fiddler that the request is being sent and a response received which is:

VB.NET:
<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<params>
 <param>
  <value>
   <array>
    <data>
     <value>
      <int>1432907</int>
     </value>
    </data>
   </array>
  </value>
 </param>
</params>
</methodResponse>

The error is: "response contains integer value where struct expected [response : array mapped to type XmlRpcStruct[] : element 0]" on this line: "Dim projectSites As XmlRpcStruct() = proxy.SapeGetProjectSites(Convert.ToInt32(gbAnalysis.Text))"

I declared it as an XmlRpcStruct() in the function, have I done that wrong? theres very little information on this protocol it seems as it's not to popular.

another response is trypically:

VB.NET:
<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<params>
 <param>
  <value>
   <int>1135778</int>
  </value>
 </param>
</params>
</methodResponse>

Is it the fact the first reponse xml is longer? any help would be great guys!

cheers

Graham
 
Top Bottom