Question XML-RPC, struct value where string expected

digitaldrew

Well-known member
Joined
Nov 10, 2012
Messages
167
Programming Experience
Beginner
I'm trying to create a new user contact using XML-RPC (the the xml-rpc.net library), but I seam to be having an issue with my structure (I think..)

First, this is what I'm working with:
bU5SpTS.jpg


and the parameters:
ksU10yQ.jpg



Now, here is what I have in my code:
VB.NET:
Imports CookComputing.XmlRpc

Public Structure gandiContactDetails
    Public city As String
    Public country As String
    Public email As String
    Public family As String
    Public given As String
    Public password As String
    Public phone As String
    Public streetaddr As String
    Public type As String
End Structure

Public Interface createContact
    <CookComputing.XmlRpc.XmlRpcMethod("contact.create")> _
    Function GandiContact(ByVal apikey As String, ByVal params As gandiContactDetails) As String
End Interface

Public Class Form1
    Public clientProtocol As XmlRpcClientProtocol
    Public createcontacts As createContact

    Private Sub btnCreateContact_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateContact.Click
   '=========== Some inputboxes here to get the required details. ===========

        Dim Parameters As gandiContactDetails
        Parameters.city = gandicity
        Parameters.country = gandicountry
        Parameters.email = gandiemail
        Parameters.family = gandifamily
        Parameters.given = gandigiven
        Parameters.password = gandipassword
        Parameters.phone = gandiphone
        Parameters.streetaddr = gandistreetaddr
        Parameters.type = "0"

        createcontacts = CType(XmlRpcProxyGen.Create(GetType(createContact)), createContact)
        clientProtocol = CType(createcontacts, XmlRpcClientProtocol)

        clientProtocol.Url = "https://rpc.websitehere.net/xmlrpc/"

        Dim response As String
        response = ""

        Try
            response = createcontacts.GandiContact(txtGandiApiKey.Text, Parameters)
            MsgBox(response)
        Catch ex As Exception
            MsgBox("Error: " & ex.Message)
        End Try
    End Sub
End Class


Finally, this is the error I continue to receive..
Error: response contains struct value where string expected (as type String) [response]


I can't see where I'm going wrong here..Any help/input would be greatly appriciated!
 
'MissingMapping' is a quite different feature than 'NullMapping'.
Are you certain XmlRpcNullMapping is defined in the library?
Of course, it was included in v.3.0 snapshot since build 241, although you should naturally use the latest 270 build.
 
Maybe I still have an outdated version of XML-RPC?
You're not using v3 of library. It's not about "outdated" or not, v.2.5 is the latest stable release, while v.3.0 which is a "beta" has included support for <nil> extension that was not part of original xml-rpc protocol.

Also, scratch the idea of NullableXmlRpcStruct (from your post 26 I thought you had updated to v3 library, which you had not), the standard XmlRpcStruct will handle <nil> values just fine when using v3 library.
If you're using v.2.5 library you will in such cases get XmlRpcInvalidXmlRpc exception "Invalid value element: <nil>" since it does not support that.
 
Thanks JohnH! I was able to get the v3 DLL referenced and re-built it. One good note is that I'm not getting the <nil> issue anymore. Now, I'm getting this:
Unable to cast object of type 'CookComputing.XmlRpc.XmlRpcStruct' to type 'ApplicationName.NullableXmlRpcStruct'.

On this line
VB.NET:
Dim response = proxy.ContactCreate(txtGandiApiKey.Text, params)

Just an update of my entire code:
VB.NET:
Option Strict On
Imports CookComputing.XmlRpc
Imports System.Web

<XmlRpcUrl("https://rpc.ote.gandi.net/xmlrpc/")> _
Public Interface IGandi : Inherits IXmlRpcProxy
    <XmlRpcMethod("contact.create")> _
    Function ContactCreate(ByVal apikey As String, ByVal params As XmlRpcStruct) As NullableXmlRpcStruct
End Interface

Public Class GandiApi
    Public Sub createGandiContact()
        If txtGandiApiKey.Text = "" Then
            MsgBox("You Must Enter Your Gandi API Key before Creating a Contact!")
            Exit Sub
        Else
            Dim params As New XmlRpcStruct
            params("given") = "John"
            params("family") = "Doe"
            params("email") = "john@doe.com"
            params("streetaddr") = "500 Main Street"
            params("city") = "Chicago"
            params("country") = "US"
            params("phone") = "+33.123456789"
            params("type") = "1"
            params("password") = "password"
            params("orgname") = "Test Organization"

            If txtgandiAuIdNumber.Text <> "" Or txtgandiCaType.Text <> "" Or txtgandiItPin.Text <> "" Or _
                txtgandiRuPassport.Text <> "" Or txtgandiSeIdent.Text <> "" Then
                Dim extra_parameters As New XmlRpcStruct
                If txtgandiAuIdNumber.Text <> "" And txtgandiAuIdType.Text <> "" Then
                    extra_parameters("x-au_registrant_id_number") = txtgandiAuIdNumber.Text
                    extra_parameters("x-au_registrant_id_type") = txtgandiAuIdType.Text
                End If
                If txtgandiCaType.Text <> "" And txtgandiCaType.Text <> "" Then
                    extra_parameters("x-ca_legaltype") = txtgandiCaType.Text
                    extra_parameters("x-ca_owner_name") = txtgandiCaName.Text
                End If
                If txtgandiItPin.Text <> "" Then
                    extra_parameters("x-it_pin") = txtgandiItPin.Text
                End If
                If txtgandiRuPassport.Text <> "" Then
                    extra_parameters("x-ru_registrant_passport_data") = txtgandiRuPassport.Text
                End If
                If txtgandiSeIdent.Text <> "" Then
                    extra_parameters("x-se_ident_number") = txtgandiSeIdent.Text
                End If
                params("extra_parameters") = extra_parameters
            End If

            Dim proxy = XmlRpcProxyGen.Create(Of IGandi)()
            Dim response = proxy.ContactCreate(txtGandiApiKey.Text, params)
            Dim handle = response("handle")
            MsgBox(handle)
        End If
    End Sub
End Class

<XmlRpcNullMapping(NullMappingAction.Ignore)> _
Public Class NullableXmlRpcStruct : Inherits XmlRpcStruct
End Class

My guess is the error has something to do with either
VB.NET:
Function ContactCreate(ByVal apikey As String, ByVal params As XmlRpcStruct) As NullableXmlRpcStruct

or

VB.NET:
Public Class NullableXmlRpcStruct : Inherits XmlRpcStruct
 
Last edited:
Unable to cast object of type 'CookComputing.XmlRpc.XmlRpcStruct' to type 'ApplicationName.NullableXmlRpcStruct'.
I guess you don't understand what I write here:
Also, scratch the idea of NullableXmlRpcStruct (from your post 26 I thought you had updated to v3 library, which you had not), the standard XmlRpcStruct will handle <nil> values just fine when using v3 library.
It means get rid of NullableXmlRpcStruct, and use the standard XmlRpcStruct. Feel free to ask for clarification when you don't understand.
 
Sorry about that, JohnH - Don't know why I overlooked what you had put there. Making that change did the trick.. Finally, it's working!

Cheers to you for all your help through this. I would have never figured it out without your assistance!!
 
Back
Top