The “membername” member is not of type base64 error from xml-rpc service call

丶灬走出姿态 提交于 2019-12-10 12:35:46

问题


I'm using Charles Cook's xml-rpc.net in an attempt to make an xml-rpc service call.

The request needs to be sent in this format:

<?xml version="1.0" encoding="iso-8859-1"?>
<methodCall>
<methodName>leads</methodName>
<params>
<param>
<value>
<struct>
<member>
 <name>key</name>
 <value>
  <string>XXXXXXXXXXX</string>
 </value>
</member>
<member>
 <name>leads</name>
 <value>
  <base64>PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPGxlYWRzPgogICA8bGVhZD4K
          ICAgICAgPGlkPjM5OTk3PC9pZD4KICAgICAgPEZpcnN0TmFtZT5Cb2IgSmltPC9GaXJzdE5hbWU+
          CiAgICAgIDxMYXN0TmFtZT5TbWl0aDwvTGFzdE5hbWU+CiAgICAgIDxBZGRyZXNzPjEyMzQgV2Vz
          :
          :
          ICAgICA8UmVjZWl2ZUFkZGxJbmZvPlllczwvUmVjZWl2ZUFkZGxJbmZvPgogICAgICA8bG9wX3dj
          X3N0YXR1cz5ObzwvbG9wX3djX3N0YXR1cz4KICAgPC9sZWFkPgo8L2xlYWRzPg==
  </base64>
 </value>
</member>
</struct>
</value>
</param>
</params>
</methodCall>

Where member name contains multiple tags in this format:

 <?xml version="1.0" encoding="UTF-8"?>
 <leads xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns="http://www.siteName.com/Leads"
   xsi:schemaLocation="http://www.siteName.com/Leads Leads.xsd"
   version="1.0">
  <lead>
  <id>39997</id>
  <first_name>Jim</first_name>
  <last_name>Smith</last_name>
  <address>1234 West 5th Street</address>
  <address2/>
  <city>Beverly Hills</city>
  <state_or_province>CA</state_or_province>
  <country>USA</country>
  <postal_code>90210</postal_code>
  <best_number>555-121-3322</best_number>
  <best_number_ext/>
  <alt_number/>
  <alt_number_ext/>
  <time_zone>Pacific</time_zone>
  <best_time>mid day</best_time>
  <request_uri>http://siteName.com/contact/
               ?source=VendorName&amp;leadid=VendorId&amp;ad=SomeAd</request_uri>
  <handoff_id>X-vendorid</handoff_id>
  </lead>
  <lead>
  <id>39987</id>
  <first_name>George</first_name>
   :
   :
  <lop_wc_status>No</lop_wc_status>
  <request_uri>http://siteName.com/contact/
               ?source=VendorName&amp;leadid=VendorId&amp;ad=SomeAd</request_uri>
 </lead>
</leads>

The documentation on the webservice method calls for one parameter that contains two values (array of values) - key and leads. The xml document containing the leads data must be packaged as a binary object. This value must be named leads and must be of type base64.

Here's what I got so far that is failing:

My struct containing the leads info-

     [Serializable]
     public struct myLeads
     {
      public string id;
      public string first_name;
      public string last_name;
     }

The interface

    public interface ILead
    {
    [CookComputing.XmlRpc.XmlRpcMethod("leads", StructParams = true)]
    string NewLead(string key, myLeads leads);
    }

Finally, I initialize the struct values and call the method:

    myLeads newLead = default(newLeads);
    Guid guid = System.Guid.NewGuid();
    newLead.id = guid.ToString();
    newLead.first_name = "Test";
    newLead.last_name = "LastNameTest";
    newLead.address = "111 Test St";

    var leadPost = (ILead)XmlRpcProxyGen.Create(typeof(ILead));
    var clientProtocol = (XmlRpcClientProtocol)leadPost;
    clientProtocol.Url =  "https://dashboard.sitename.com/webservices/rpc/xmlrpc";
    try
    {
        result = leadPost.NewLead("XXXKeyXXX", newLead);
        Label1.Text = result;
    }
    catch (Exception ex)
    {
        throw ex;
    }

My code throws the error in the try block: The leads member is not of type base64! How do I set this up properly?

Thanks in advance!


回答1:


The parameter to the leads method should be a struct or class containing two members, for example:

public struct leadsParam
{
   public string key;
   public byte[] leads;
}

and the interface would be

public interface ILead
{
    [XmlRpcMethod("leads")]
    string NewLead(leadsParam leads);
}


来源:https://stackoverflow.com/questions/10855156/the-membername-member-is-not-of-type-base64-error-from-xml-rpc-service-call

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!