C#XMLRPC自定义字段

时间:2011-11-15 11:41:25

标签: c# xml-rpc

我试图用C#编写一个程序而且我被卡住了。该程序假设通过xmlrpc在wordpress上创建一个帖子。我可以成功创建帖子,但是我在为帖子创建自定义字段时遇到问题。因此,当我打开创建的帖子时,自定义字段永远不存在。我希望你们中的一些大师可以帮助我,因为我现在被困3天而且无法弄清楚该怎么做,感到绝对无助:(

下面是一些代码:

public struct customField
        {
            public string key;
            public string value; 
        }
        public struct newPost
        {
            public string[] categories;
            public string title;
            public string description;
            public string mt_excerpt;
            public customField[] cf;
        }
public interface IcreatePost
       {
           [CookComputing.XmlRpc.XmlRpcMethod("metaWeblog.newPost")]
           string NewPost(int blogId, string strUserName,
               string strPassword, newPost content, int publish);
       }

这是我如何设置对象的值

    customField newCustomField2 = default(customField);

    newCustomField2.key = "some data";

    newCustomField2.value = "some data";


    newPost newBlogPost = default(newPost);
    newBlogPost.title = "Some Title";
    newBlogPost.description = "Some Content";
    newBlogPost.cf = new customField[] { newCustomField2 };
createPost(newBlogPost);

函数调用:

public void createPost(newPost np)
        {

            string postid;
            icp = (IcreatePost)XmlRpcProxyGen.Create(typeof(IcreatePost));
            clientProtocol = (XmlRpcClientProtocol)icp;
            clientProtocol.Url = "http://127.0.0.1/xmlrpc.php";
            try
            {
                postid = icp.NewPost(1, "admin", "1234", np, 1); 

            }
            catch (Exception ex)
            {
                MessageBox.Show("createPost ERROR ->"+ ex.Message);
            }
        }

1 个答案:

答案 0 :(得分:2)

我唯一猜测的是你的参数命名不匹配。我见过的文档说newPost结构中的字段应该是custom_fields而不是cf

public struct newPost
{
    public string[] categories;
    public string title;
    public string description;
    public string mt_excerpt;
    public customField[] custom_fields;
}