我正在使用 Charles Cook 的 xml-rpc.net 来尝试进行 xml-rpc 服务调用。
请求需要以这种格式发送:
<?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>
其中成员名称包含此格式的多个标签:
<?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&leadid=VendorId&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&leadid=VendorId&ad=SomeAd</request_uri>
</lead>
</leads>
关于 webservice 方法的文档需要一个包含两个值(值数组)的参数 - 键和线索。包含潜在客户数据的 xml 文档必须打包为二进制对象。此值必须命名为潜在客户,并且必须是 base64 类型。
这是我到目前为止失败的结果:
我的结构包含潜在客户信息-
[Serializable]
public struct myLeads
{
public string id;
public string first_name;
public string last_name;
}
界面
public interface ILead
{
[CookComputing.XmlRpc.XmlRpcMethod("leads", StructParams = true)]
string NewLead(string key, myLeads leads);
}
最后,我初始化结构值并调用方法:
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;
}
我的代码在 try 块中抛出错误:leads 成员不是 base64 类型!如何正确设置?
提前致谢!