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!
 
Error: response contains struct value where string expected (as type String) [response]
Your image says "contact.create" returns "struct-Contact Information", while in your code GandiContact interface function is defined "As String".
 
Thanks for responding and pointing that out John. I seamed to have completely missed it :numbness:

I've changed that line around to something like this
VB.NET:
Function GandiContact(ByVal apikey As String, ByVal params As gandiContactDetails) As XmlRpcStruct

My next question would be putting that back into a string to read it at the end. Is this possible?

If I make the change I told you about above, my response string now tells me "Value of type 'CookComputing.XmlRpc.XmlRpcStruct' cannot be converted to 'String"."

Thanks!
 
I think you're supposed to include a "Contact Information" structure definition and use that as return type. XmlRpc library should then convert the response to a value of that structure type.
 
@JohnH - Thanks so much for your response! I kind of understand what you're saying, but I wouldn't be able to use the structure I already have setup? After thinking about it some more I'm guessing that somewhere (maybe in my current structure) I need to actually specify which param is the "password", which is "family"..etc?

I notice they provide this example (although it appears to be in python)
JVkG16V.jpg


I found a separate XMLRPC example online which I've tried altering to do as I need, but still no go. My current code is now:

VB.NET:
'First setting up my structure

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

'Now some XMLRPC stuff
<XmlRpcUrl("https://rpc.ote.gandi.net/xmlrpc/")> _
Public Interface IWP
    Inherits IXmlRpcProxy
    <XmlRpcMethod("contact.create")> _
    Function GandiContact(ByVal apikey As String, ByVal args As gandiContactDetails) As XmlRpcStruct
End Interface

Public Class Form1
     Private Sub btnCreateContact_Click(ByVal sender As System.Object, ByVal  e As System.EventArgs) Handles btnCreateContact.Click
        Dim Parameters As gandiContactDetails
        Parameters.city = gandicity
        Parameters.country = gandicountry.ToUpper
        Parameters.email = gandiemail
        Parameters.family = gandifamily
        Parameters.given = gandigiven
        Parameters.password = gandipassword
        Parameters.phone = gandiphone
        Parameters.streetaddr = gandistreetaddr
        Parameters.type = "0"

        Dim response As XmlRpcStruct = Nothing

        Dim proxy As IWP = XmlRpcProxyGen.Create(Of IWP)()
        response = proxy.GandiContact(txtGandiApiKey.Text, Parameters)
        MsgBox(response)

    End Sub
End Class

When running that code.. I get an 'Object reference not set to an instance of an object' error.. I'll keep messing with it some more, thank you again for your input - This is my first time ever messing with XMLRPC and it's been a total learning process lol
 
You should read the documentation, this looks like the same: Contact API Reference ? Gandi API 3.3.24 documentation
The return structure is nothing like the params input structure.

As for defining the return as type XmlRpcStruct, I did see that done somewhere too, it was then used as some kind of dictionary it appears, for example response("brand_number").
When running that code.. I get an 'Object reference not set to an instance of an object' error..
And only you know where.
This is my first time ever messing with XMLRPC and it's been a total learning process lol
Don't recall I've ever used it.
 
@JohnH - Thanks for replying! You're exactly correct on the documentation and I have that open.

Since the structure going in only needs a few of those (family, phone, email..etc), and they are sending back lots of other information, I basically need a second structure that has all of these in it?

Also, you're idea with the response sounds correct. Looking at the screenshot in my most recent reply it seams they are doing contact['handle'] which should get specifically the "Handle" out of the reply. That's exactly what i'm looking to do.

Thank you!
 
Just wanted to post another update JohnH - After reading you reply I started to dip in a little further... This is basically where I'm at:

I created a separate structure for the reply. While setting that up I noticed some of the returns are structures as well. With that in mind, I then created new structures for each of those (with any returns in them if needed)... This is basically how my code looks now

VB.NET:
Imports CookComputing.XmlRpc

'=== Structures ====
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 Structure gandiContactReply
    Public brand_number As String
    Public handle As String
    Public bu As bu
    Public city As String
    Public community As Boolean
    Public country As country
    Public data_obfuscated As Integer
    Public email As String
    Public extra_parameters As extra_parameters
    Public family As String
    Public fax As String
    Public given As String
    Public id As Integer
    Public is_corporate As Boolean
    Public jo_announce_number As String
    Public jo_announce_page As String
    Public jo_declaration_date As String
    Public jo_publication_date As String
    Public lang As String
    Public mail_obfuscated As Integer
    Public mobile As String
    Public newsletter As Integer
    Public orgname As String
    Public phone As String
    Public reachability As String
    Public security_question_answer As String
    Public security_question_num As Integer
    Public shippingaddress As shippingaddress
    Public siren As String
    Public state As String
    Public streetaddr As String
    Public third_part_resell As Integer
    Public type As Integer
    Public validation As String
    Public vat_number As String
    Public zip As String
End Structure

Public Structure bu
    Public id As Integer
    Public name As String
End Structure

Public Structure country
End Structure

Public Structure extra_parameters
End Structure

Public Structure shippingaddress
    Public city As String
    Public country As String
    Public family As String
    Public given As String
    Public orgname As String
    Public state As String
    Public streetaddr As String
    Public streetaddr2 As String
    Public zip As String
End Structure

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

Public Class GandiApi
    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

        Dim Parameters As gandiContactDetails
        Parameters.city = gandicity
        Parameters.country = gandicountry.ToUpper
        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.ote.gandi.net/xmlrpc/"

        Dim response As XmlRpcStruct = Nothing

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

Looking at the documentation I think this looks correct, but after running I now get this error:

error.jpg
 
I just tested the StateName service listed at XML-RPC.Net and can confirm that:
  • you can use XmlRpcStruct in place of a specifically defined structure both for input and output, and
  • XmlRpcStruct is a Hashtable where you can add or get the structure members and values by key (name as string).
 
1.15 Can I specify struct members as optional?

Also in your last code return type is gandiContactReply, let the compiler help you by inferring it:
Dim result = createcontacts.GandiContact(txtGandiApiKey.Text, Parameters)
 
Thanks for responding John! I'll give the XML-RPC link a look some more.. Do I need to specify all params when building the initial structure and just specify if they are optional or not?

Also, I've tried using XmlRpcStruct in place of the structures, for example:[
VB.NET:
Public Structure gandiContactReply
    Public brand_number As String
    Public handle As String
    Public bu As bu
    Public city As String
    Public community As Boolean
    Public country As XmlRpcStruct
    Public data_obfuscated As Integer
    Public email As String
    Public extra_parameters As XmlRpcStruct
    Public family As String
    Public fax As String
    Public given As String
    Public id As Integer
    Public is_corporate As Boolean
    Public jo_announce_number As String
    Public jo_announce_page As String
    Public jo_declaration_date As String
    Public jo_publication_date As String
    Public lang As String
    Public mail_obfuscated As Integer
    Public mobile As String
    Public newsletter As Integer
    Public orgname As String
    Public phone As String
    Public reachability As String
    Public security_question_answer As String
    Public security_question_num As Integer
    Public shippingaddress As shippingaddress
    Public siren As String
    Public state As String
    Public streetaddr As String
    Public third_part_resell As Integer
    Public type As Integer
    Public validation As String
    Public vat_number As String
    Public zip As String
End Structure

But I still get this error:
response contains struct value with missing non-optional members: city family state orgname streetaddr country zip streetaddr2 given [response: struct mapped to type gandiContactReply: member shippingaddress mapped to type shippingaddress: struct mapped to type shippingaddress]

Is it required to specify if they are optional? Also, not really sure about your last line of code. Thanks!
 
Just wanted to post another update since I've been doing some more messing around. JohnH - I looked over the link you sent me about the structure ignore/error.. I think I've got that put into the code properly now for the required parameters.

For those who might just be reading this thread..I'll try and cover all of this from the beggining as it might make a little more sense now..

-I need to create a contact using this method. As you will see, it requires an API key string and a structure of these parameters. It will then return the response in a structure as well. Keep in mind, I've also added a few extra parameters which is yet another structure, but not a required one.

-As I mentioned above, the return will come back as a structure as well. This is what the return structure will look like.

I've re-done my code now with some changes to the structures. I'm now including all of the different parameters which I wasn't doing before..I've also tried to comment out some more to explain what I'm trying to do

VB.NET:
Imports CookComputing.XmlRpc

'===== FIRST STRUCTURE parameters I am sending =====
<XmlRpcMissingMapping(MappingAction.Ignore)> _
Public Structure gandiContactDetails
    <XmlRpcMissingMapping(MappingAction.Error)> _
    Public city As String
    <XmlRpcMissingMapping(MappingAction.Error)> _
    Public country As String
    <XmlRpcMissingMapping(MappingAction.Error)> _
    Public email As String
    <XmlRpcMissingMapping(MappingAction.Error)> _
    Public family As String
    <XmlRpcMissingMapping(MappingAction.Error)> _
    Public given As String
    <XmlRpcMissingMapping(MappingAction.Error)> _
    Public password As String
    <XmlRpcMissingMapping(MappingAction.Error)> _
    Public phone As String
    <XmlRpcMissingMapping(MappingAction.Error)> _
    Public streetaddr As String
    <XmlRpcMissingMapping(MappingAction.Error)> _
    Public type As String
    Public accept_contract As Boolean
    Public brand_number As String
    Public community As Boolean
    Public community_hash As String
    Public community_referer As String
    Public data_obfuscated As Boolean
    Public extra_parameters As extra_parameters
    Public fax As String
    Public jo_announce_number As String
    Public jo_announce_page As String
    Public jo_declaration_date As String
    Public jo_publication_date As String
    Public lang As String
    Public mail_obfuscated As String
    Public mobile As String
    Public newsletter As Integer
    Public orgname As String
    Public security_question_answer As String
    Public security_question_num As String
    Public siren As String
    Public state As String
    Public third_part_resell As String
    Public vat_number As String
    Public zip As String
End Structure

'===== NEXT, STRUCTURE OF SPECIAL PARAMETERS =====
<XmlRpcMissingMapping(MappingAction.Ignore)> _
Public Structure extra_parameters
    Public birth_city As String
    Public birth_country As String
    Public birth_date As String
    Public birth_department As String
    Public brand_number As String
    Public duns As String
    Public waldec As String
    Public aero_ens_authid As String
    Public aero_ens_authkey As String
    Public au_registrant_id_number As String
    Public au_registrant_id_type As String
    Public ca_legaltype As String
    Public ca_owner_name As String
    Public coop_sponsor As String
    Public cy_reg_identity_no As String
    Public document_country As String
    Public document_type As String
    Public document_value As String
    Public es_admin_identification As String
    Public es_admin_tipo_identification As String
    Public es_bill_identification As String
    Public es_bill_tipo_identification As String
    Public es_identification As String
    Public es_legalform As String
    Public es_owner_identification As String
    Public es_owner_legalform As String
    Public es_owner_tipo_identification As String
    Public es_tech_identification As String
    Public es_tech_tipo_identification As String
    Public es_tipo_identification As String
    Public fi_based_on_person_name As String
    Public fi_business_number As String
    Public fi_ident_number As String
    Public fi_name_registration_id As String
    Public fi_name_registration_number As String
    Public hk_registrant_birth_date As String
    Public hk_registrant_document_number As String
    Public hk_registrant_document_origin_country As String
    Public hk_registrant_document_type As String
    Public hk_registrant_other_document_type As String
    Public hu_idnumber As String
    Public hu_owner_vatid As String
    Public ir_login_id As String
    Public ir_login_password As String
    Public it_pin As String
    Public kr_reg_identity_no As String
    Public lv_idnumber As String
    Public my_admin_contact_password As String
    Public my_admin_contact_username As String
    Public my_business_number As String
    Public my_organization_type As String
    Public no_registrant_identity As String
    Public nu_registrant_idnumber As String
    Public nu_registrant_vatid As String
    Public nyc_extcontact As String
    Public pro_authority As String
    Public pro_authoritywebsite As String
    Public pro_licensenumber As String
    Public pro_profession As String
    Public pt_arbitration As String
    Public pt_registrant_vatid As String
    Public pt_roid As String
    Public quebec_intendeduse As String
    Public ro_registrant_idnumber As String
    Public rs_reg_identity_no As String
    Public rs_reg_tax_no As String
    Public ru_registrant_passport_data As String
    Public se_ident_number As String
    Public sg_idnumber As String
    Public sk_registrant_idnumber As String
    Public travel_uin As String
    Public xxx_membership_contact As String
    Public xxx_sponsored_community As String
End Structure

'===== THIRD, SETUP THE STRUCTURE FOR THE RETURN PARAMETERS =====
'===== some of these are also structures - I used XmlRpcStruct =====
Public Structure gandiContactReply
    Public brand_number As String
    Public handle As String
    Public bu As XmlRpcStruct
    Public city As String
    Public community As Boolean
    Public country As XmlRpcStruct
    Public data_obfuscated As Integer
    Public email As String
    Public extra_parameters As XmlRpcStruct
    Public family As String
    Public fax As String
    Public given As String
    Public id As Integer
    Public is_corporate As Boolean
    Public jo_announce_number As String
    Public jo_announce_page As String
    Public jo_declaration_date As String
    Public jo_publication_date As String
    Public lang As String
    Public mail_obfuscated As Integer
    Public mobile As String
    Public newsletter As Integer
    Public orgname As String
    Public phone As String
    Public reachability As String
    Public security_question_answer As String
    Public security_question_num As Integer
    Public shippingaddress As XmlRpcStruct
    Public siren As String
    Public state As String
    Public streetaddr As String
    Public third_part_resell As Integer
    Public type As Integer
    Public validation As String
    Public vat_number As String
    Public zip As String
End Structure

'===== FOURTH, I INITIATE THE METHOD =====
Public Interface createContact
    <CookComputing.XmlRpc.XmlRpcMethod("contact.create")> _
    Function GandiContact(ByVal apikey As String, ByVal params As gandiContactDetails) As gandiContactReply
End Interface

'===== NOW COMES THE MAIN FORM WITH A BUTTON =====
Public Class Form1
    Public clientProtocol As XmlRpcClientProtocol
    Public createcontacts As createContact

    '===== SOMEONE CLICKS THE BUTTON TO CREATE CONTACT =====
    Private Sub btnCreateContact_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateContact.Click

    '===== I WILL HAVE SOME INPUTBOXES HERE TO GET NAME/EMAIL =====
    '===== and other required information for structure gandiContactDetails =====

        Dim Parameters As gandiContactDetails
        Parameters.city = gandicity
        Parameters.country = gandicountry.ToUpper
        Parameters.email = gandiemail
        Parameters.family = gandifamily
        Parameters.given = gandigiven
        Parameters.password = gandipassword
        Parameters.phone = gandiphone
        Parameters.streetaddr = gandistreetaddr
        Parameters.type = "0"
        Parameters.accept_contract = True
        Parameters.brand_number = Nothing
        Parameters.community = False
        Parameters.community_hash = Nothing
        Parameters.community_referer = Nothing
        Parameters.data_obfuscated = False
        Parameters.extra_parameters.birth_city = Nothing
        Parameters.extra_parameters.birth_country = Nothing
        Parameters.extra_parameters.birth_date = Nothing
        Parameters.extra_parameters.birth_department = Nothing
        Parameters.extra_parameters.brand_number = Nothing
        Parameters.extra_parameters.duns = Nothing
        Parameters.extra_parameters.waldec = Nothing
        Parameters.extra_parameters.aero_ens_authid = Nothing
        Parameters.extra_parameters.aero_ens_authkey = Nothing
        Parameters.extra_parameters.au_registrant_id_number = txtgandiAuIdNumber.Text
        Parameters.extra_parameters.au_registrant_id_type = txtgandiAuIdType.Text
        Parameters.extra_parameters.ca_legaltype = txtgandiCaType.Text
        Parameters.extra_parameters.ca_owner_name = txtgandiCaName.Text
        Parameters.extra_parameters.coop_sponsor = Nothing
        Parameters.extra_parameters.cy_reg_identity_no = Nothing
        Parameters.extra_parameters.document_country = Nothing
        Parameters.extra_parameters.document_type = Nothing
        Parameters.extra_parameters.document_value = Nothing
        Parameters.extra_parameters.es_admin_identification = Nothing
        Parameters.extra_parameters.es_admin_tipo_identification = Nothing
        Parameters.extra_parameters.es_bill_identification = Nothing
        Parameters.extra_parameters.es_bill_tipo_identification = Nothing
        Parameters.extra_parameters.es_identification = Nothing
        Parameters.extra_parameters.es_legalform = Nothing
        Parameters.extra_parameters.es_owner_identification = Nothing
        Parameters.extra_parameters.es_owner_legalform = Nothing
        Parameters.extra_parameters.es_owner_tipo_identification = Nothing
        Parameters.extra_parameters.es_tech_identification = Nothing
        Parameters.extra_parameters.es_tech_tipo_identification = Nothing
        Parameters.extra_parameters.es_tipo_identification = Nothing
        Parameters.extra_parameters.fi_based_on_person_name = Nothing
        Parameters.extra_parameters.fi_business_number = Nothing
        Parameters.extra_parameters.fi_ident_number = Nothing
        Parameters.extra_parameters.fi_name_registration_id = Nothing
        Parameters.extra_parameters.fi_name_registration_number = Nothing
        Parameters.extra_parameters.hk_registrant_birth_date = Nothing
        Parameters.extra_parameters.hk_registrant_document_number = Nothing
        Parameters.extra_parameters.hk_registrant_document_origin_country = Nothing
        Parameters.extra_parameters.hk_registrant_document_type = Nothing
        Parameters.extra_parameters.hk_registrant_other_document_type = Nothing
        Parameters.extra_parameters.hu_idnumber = Nothing
        Parameters.extra_parameters.hu_owner_vatid = Nothing
        Parameters.extra_parameters.ir_login_id = Nothing
        Parameters.extra_parameters.ir_login_password = Nothing
        Parameters.extra_parameters.it_pin = txtgandiItPin.Text
        Parameters.extra_parameters.kr_reg_identity_no = Nothing
        Parameters.extra_parameters.lv_idnumber = Nothing
        Parameters.extra_parameters.my_admin_contact_password = Nothing
        Parameters.extra_parameters.my_admin_contact_username = Nothing
        Parameters.extra_parameters.my_business_number = Nothing
        Parameters.extra_parameters.my_organization_type = Nothing
        Parameters.extra_parameters.no_registrant_identity = Nothing
        Parameters.extra_parameters.nu_registrant_idnumber = Nothing
        Parameters.extra_parameters.nu_registrant_vatid = Nothing
        Parameters.extra_parameters.nyc_extcontact = Nothing
        Parameters.extra_parameters.pro_authority = Nothing
        Parameters.extra_parameters.pro_authoritywebsite = Nothing
        Parameters.extra_parameters.pro_licensenumber = Nothing
        Parameters.extra_parameters.pro_profession = Nothing
        Parameters.extra_parameters.pt_arbitration = Nothing
        Parameters.extra_parameters.pt_registrant_vatid = Nothing
        Parameters.extra_parameters.pt_roid = Nothing
        Parameters.extra_parameters.quebec_intendeduse = Nothing
        Parameters.extra_parameters.ro_registrant_idnumber = Nothing
        Parameters.extra_parameters.rs_reg_identity_no = Nothing
        Parameters.extra_parameters.rs_reg_tax_no = Nothing
        Parameters.extra_parameters.ru_registrant_passport_data = txtgandiRuPassport.Text
        Parameters.extra_parameters.se_ident_number = txtgandiSeIdent.Text
        Parameters.extra_parameters.sg_idnumber = Nothing
        Parameters.extra_parameters.sk_registrant_idnumber = Nothing
        Parameters.extra_parameters.travel_uin = Nothing
        Parameters.extra_parameters.xxx_membership_contact = Nothing
        Parameters.extra_parameters.xxx_sponsored_community = Nothing
        Parameters.fax = Nothing
        Parameters.jo_announce_number = Nothing
        Parameters.jo_announce_page = Nothing
        Parameters.jo_declaration_date = Nothing
        Parameters.jo_publication_date = Nothing
        Parameters.lang = Nothing
        Parameters.mail_obfuscated = Nothing
        Parameters.mobile = Nothing
        Parameters.newsletter = 0
        Parameters.orgname = Nothing
        Parameters.security_question_answer = Nothing
        Parameters.security_question_num = Nothing
        Parameters.siren = Nothing
        Parameters.state = Nothing
        Parameters.third_part_resell = Nothing
        Parameters.vat_number = Nothing
        Parameters.zip = Nothing

        '===== NEXT, CREATE THE REQUEST =====
        createcontacts = CType(XmlRpcProxyGen.Create(GetType(createContact)), createContact)
        clientProtocol = CType(createcontacts, XmlRpcClientProtocol)
        clientProtocol.Url = "https://rpc.ote.gandi.net/xmlrpc/"

        '===== DIM THE REPLY AS STRUCTURE =====
        Dim response As XmlRpcStruct = Nothing

        '===== FINALLY, GET AND VIEW THE handle OF THE response =====
        response("handle") = createcontacts.GandiContact(txtGandiApiKey.Text, Parameters)
        msgbox(response)
    End Sub
End Class

I don't seam to be getting the same error as I was before..Now I'm getting:
Server returned a fault exception: [500037] Error on object: OBJECT_UNKNOWN (CAUSE_BADPARAMETER) [extra_parameters: Unknown ca_owner_name key]

Not really sure why that would be happening as it's setup just as I see it in the documentation.
 
ExtraParameters has a "x-ca_owner_name" key, not "ca_owner_name". Since you can't use the character "-" in a member name in VB.Net code I guess you have to map that with XmlRpcMember attribute.

Also, not sure if you understood earlier that you can use XmlRpcStruct, that may make coding much simpler when there are all these extensive structures to define, this would be at the cost of type safety and having to copy/paste the keys as strings each time. Still, with a huge web service API you could spend ages just defining the structures. Example with only XmlRpcStructs:
<XmlRpcUrl("https://rpc.ote.gandi.net/xmlrpc/")> _
Public Interface IGandi
    <XmlRpcMethod("contact.create")> _
    Function ContactCreate(ByVal apikey As String, ByVal params As XmlRpcStruct) As XmlRpcStruct

    ' add more web service methods
End Interface

sample usage:
        Dim params As New XmlRpcStruct
        params("city") = gandicity
        'set other params members, including all required ones
       
        Dim extra_parameters As New XmlRpcStruct
        extra_parameters("x-au_registrant_id_number") = txtgandiAuIdNumber.Text
        'set other extra_parameters members
        params("extra_parameters") = extra_parameters

        Dim proxy = XmlRpcProxyGen.Create(Of IGandi)()
        Dim response = proxy.ContactCreate(txtGandiApiKey.Text, params)

        Dim handle = response("handle")

By the way, setting a structure member to default value as in your last post (all the 'Nothing' lines) is pointless, but if you're using XmlRpcStruct you do have to add the required keys (and a value) at minimum.
 
JohnH - Thanks very much for your reply, and for your example. I appreciate you taking the time to do that since you were able to cut the code way down, and I was making things way more confusing then they really needed to be! I took your example and added all the required parameters. I also added some checks for the special parameters.. This is basically what I have now:

VB.NET:
'== Input boxes to get required paramters ==
        Dim gandiStreetAddr As String = InputBox("Enter Your Street Address" & vbCrLf & vbCrLf & "For example: 500 Main Street", "", "")
        If gandiStreetAddr = " " Then
            MsgBox("You Must Enter a Valid Street Address")
            Exit Sub
        ElseIf gandiStreetAddr = "" Then
            MsgBox("You Must Enter Your Street Address")
            Exit Sub
        End If

'== Required parameters ==
                Dim params As New XmlRpcStruct
                params("city") = gandicity
                params("country") = gandicountry.ToUpper
                params("email") = gandiemail
                params("family") = gandifamily
                params("given") = gandigiven
                params("password") = gandipassword
                params("phone") = gandiphone
                params("streetaddr") = gandiStreetAddr
                params("type") = "0"

'== A check to see if extra parameters have been entered. If so, put those in there too ==
                If txtgandiAuIdNumber.Text IsNot "" Or txtgandiCaType.Text IsNot "" Or txtgandiItPin.Text IsNot "" Or txtgandiRuPassport.Text IsNot "" Or txtgandiSeIdent.Text IsNot "" Then
                    Dim extra_parameters As New XmlRpcStruct
                    If txtgandiAuIdNumber.Text And txtgandiAuIdType.Text IsNot "" 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 txtgandiCaName.Text IsNot "" Then
                        extra_parameters("x-ca_legaltype") = txtgandiCaType.Text
                        extra_parameters("x-ca_owner_name") = txtgandiCaName.Text
                    End If
                    If txtgandiItPin.Text IsNot "" Then
                        extra_parameters("x-it_pin") = txtgandiItPin.Text
                    End If
                    If txtgandiRuPassport.Text IsNot "" Then
                        extra_parameters("x-ru_registrant_passport_data") = txtgandiRuPassport.Text
                    End If
                    If txtgandiSeIdent.Text IsNot "" Then
                        extra_parameters("x-se_ident_number") = txtgandiSeIdent.Text
                    End If
                    'set other extra_parameters members
                    params("extra_parameters") = extra_parameters
                End If

'== Create request and view result ==
                Dim proxy = XmlRpcProxyGen.Create(Of IGandi)()
                Dim response = proxy.ContactCreate(txtGandiApiKey.Text, params)

                Dim handle = response("handle")
                MsgBox(handle)

When running the code above I get:
Object reference not set to an instance of an object.

Any idea what I could be missing here? Thank you again!
 
Last edited:
When running the code above I get:
Object reference not set to an instance of an object.

Any idea what I could be missing here? Thank you again!
As I said before only you know where in a posted code throws exception, you have to tell what line throws that exception. Debugger will stop and highlight that line, and you can there also inspect the various expressions to see what is a null reference (Nothing).

At a guess:
params("country") = gandicountry.ToUpper
if gandicountry is Nothing, then Nothing.ToUpper would throw null reference exception.
 
Back
Top