Been trying to wrap my head around manipulating a php wordpress install with a .NET client.
Not much clear cut info out there so I figured I would post a quick example to give those interested a starting point.
First things first. You need the CookComputing.XmlRpc library. You can download the latest version here.
You need to extract the zip file using winzip, winrar or another non system extractor.
For some reason the bin directory is not visible if using the system extractor even if you are running as Admin and have all folder view options on.
Next, start up visual studio and create a new standard windows forms application. You should not target a compact framework. I had problems with the .net 4 client profile framework so I changed the framework to standard .net 4.0
Now you will need to add two references to the project. Click add reference from visual studio and select browse. You need to browse to the bin directory of the xml-rpc.net.2.5.0 directory you previously extracted. Add a reference to CookComputing.XmlRpcV2.dll and IStateName.dll
Go back to your form and add a single button. View the form code window and add the following.
Imports CookComputing.XmlRpc
Imports System
Public Class Form1 'your form name
Public Structure category
Public categoryId As Object
Public parentId As Object
Public description As Object
Public categoryName As Object
Public htmlUrl As Object
Public rssUrl As Object
End Structure
'// important to have the correct wordpress xmlrpc.php path. If in doubt, use your browser and navigate to it '//first.
<XmlRpcUrl("http://yoursite.com/wordpress/xmlrpc.php")> _
Public Interface IWP
Inherits IXmlRpcProxy
<XmlRpcMethod("wp.getCategories")> _
Function getCategories(ByVal args() As String) As category()
End Interface
'// your button1 code....
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim proxy As IWP = XmlRpcProxyGen.Create(Of IWP)()
Dim args() As String = {"http:/yoursite.com", _
"AdminUserName", "AdminPassword"}
Dim categories() As category
categories = proxy.getCategories(args)
For Each category In categories
Debug.Print(category.categoryId)
Debug.Print(category.categoryName)
Debug.Print(category.description)
Debug.Print(category.htmlUrl)
Debug.Print(category.rssUrl)
Next
End Sub
End Class
That should do it.
There is another great blog that defines more functions step by step in C# and VB.net here
Not much clear cut info out there so I figured I would post a quick example to give those interested a starting point.
First things first. You need the CookComputing.XmlRpc library. You can download the latest version here.
You need to extract the zip file using winzip, winrar or another non system extractor.
For some reason the bin directory is not visible if using the system extractor even if you are running as Admin and have all folder view options on.
Next, start up visual studio and create a new standard windows forms application. You should not target a compact framework. I had problems with the .net 4 client profile framework so I changed the framework to standard .net 4.0
Now you will need to add two references to the project. Click add reference from visual studio and select browse. You need to browse to the bin directory of the xml-rpc.net.2.5.0 directory you previously extracted. Add a reference to CookComputing.XmlRpcV2.dll and IStateName.dll
Go back to your form and add a single button. View the form code window and add the following.
Imports CookComputing.XmlRpc
Imports System
Public Class Form1 'your form name
Public Structure category
Public categoryId As Object
Public parentId As Object
Public description As Object
Public categoryName As Object
Public htmlUrl As Object
Public rssUrl As Object
End Structure
'// important to have the correct wordpress xmlrpc.php path. If in doubt, use your browser and navigate to it '//first.
<XmlRpcUrl("http://yoursite.com/wordpress/xmlrpc.php")> _
Public Interface IWP
Inherits IXmlRpcProxy
<XmlRpcMethod("wp.getCategories")> _
Function getCategories(ByVal args() As String) As category()
End Interface
'// your button1 code....
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim proxy As IWP = XmlRpcProxyGen.Create(Of IWP)()
Dim args() As String = {"http:/yoursite.com", _
"AdminUserName", "AdminPassword"}
Dim categories() As category
categories = proxy.getCategories(args)
For Each category In categories
Debug.Print(category.categoryId)
Debug.Print(category.categoryName)
Debug.Print(category.description)
Debug.Print(category.htmlUrl)
Debug.Print(category.rssUrl)
Next
End Sub
End Class
That should do it.
There is another great blog that defines more functions step by step in C# and VB.net here
gives me a 403 username/password invalid.
ReplyDeletefix:
<.htaccess>
SecFilterInheritance Off
next is a 500 internal server error....havent found out why yet. will post when i do.
.net 4.0(not client)
vs2010
Not sure, only thing I can think of is that the wordpress settings to allow xmlrpc posts is not enabled?
ReplyDeleteI have run a modified version of this on several hosts and not had problems. Could be host issues or again the xmlrpc posts permissions.