2011-11-15 125 views
0

我試圖寫一個程序在C#中,我卡住了。該程序假設通過xmlrpc在wordpress上創建一個帖子。我可以成功創建帖子,但是在爲帖子創建自定義字段時遇到問題。所以當我打開創建的帖子時,自定義字段永遠不會存在。我希望你們中的一些大師可以幫助我爲我停留3天,現在無法弄清楚做什麼,感覺絕對無助:(C#XMLRPC自定義字段

繼承人一些代碼:

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); 
      } 
     } 

回答

2

我只能猜測在這裏將有一個納明g參數不匹配。我見過的文檔說newPost結構裏面的字段應該是custom_fields而非cf

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

太感謝你了!問題解決了:) – user1047463