Write .net against XERO

 

Useful Links:

Steps to Get Started

Follow these steps.

Create SSL Certification

  1. Install Open SSL from link provided above.
  2. Open command prompt (Run as administrator)
  3. Navigate to bin folder of openssl e.g. “C:\OpenSSL-Win32\bin”
  4. Run following lines
openssl genrsa -out privatekey.pem 1024
openssl req -new -x509 -key privatekey.pem -out publickey.cer -days 365
openssl pkcs12 -export -out public_privatekey.pfx -inkey privatekey.pem -in publickey.cer

Copy .pem, .pfx & .cer files into solution for safe keeping. You will need to redo this prcess in 365 days as ssl will expire.

Install XeroAPI.Net into Visual Studio

Install using Package Manager Console – http://www.nuget.org/packages/XeroAPI.Net

Register your Application to Xero

  1. Go to https://api.xero.com/Application/Add
  2. Select public or private
  3. Give application name and upload .cer file
  4. Copy & Save Consumer Key

Write some code

 

  Protected Sub loadClientInvoices()

        Dim session As IOAuthSession = New XeroApi.OAuth.XeroApiPrivateSession("xxxx", "xxxxx", New X509Certificate2(Request.PhysicalApplicationPath + "\openssl\public_privatekey.pfx", "xxxx"))

        Dim repository As New Repository(session)

        Dim invoicesforClient As List(Of XeroApi.Model.Invoice) = (From x In repository.Invoices Where x.Contact.ContactID = New Guid("af5d6305-b5eb-441f-a5fb-8c9ea9c960ce")).ToList

        For Each invoice In invoicesforClient
            Response.Write(invoice.InvoiceNumber + "<BR>")
        Next

    End Sub
Advertisements

Invalid assembly public key

With some existing clients starting to migrate from SharePoint 2007 to SharePoint 2010 we ran into an issue installing our existing wsp solutions.

 

The way we write wsp’s is very manual in that everything is written from scratch and we use visual studio cab builder to write the wsp. I’m not too sure if this is just a coding mistake that SharePoint 2007 didn’t care about or whether its a property that has changed recently….(let me know if you have a reason)

 

So when we try to deploy to SharePoint 2010 using our powershell commands it errors out with:

 

Invailid assembly public key. <Exception from HRESULT: 0x8013141E>

image

 

Reason

This is our manifest file

 

<?xml version="1.0" encoding="utf-8" ?>
<Solution xmlns="http://schemas.microsoft.com/sharepoint/"
          SolutionId="cf43760c-21e5-42a7-9b30-b7f956e6c267">
    <Assemblies>
        <Assembly DeploymentTarget="GlobalAssemblyCache" Location="SOPE.ListQuery.dll">
            <SafeControls>
                <SafeControl Assembly="SOPE.ListQuery, Version=1.0.0.0, Culture=neutral, PublicKey=5232633792b38efa"
                             Namespace="SOPE.ListQuery"
                             TypeName="*"
                             Safe="True"/>
            </SafeControls>
        </Assembly>
    </Assemblies>
</Solution>

 

Solution

 

Basically it doesn’t understand “PublicKey” and is looking for “PublicKeyToken”. Change the attribute name and rebuilding wsp resolves this issue.

 

<?xml version="1.0" encoding="utf-8" ?>
<Solution xmlns="http://schemas.microsoft.com/sharepoint/"
          SolutionId="cf43760c-21e5-42a7-9b30-b7f956e6c267">
    <Assemblies>
        <Assembly DeploymentTarget="GlobalAssemblyCache" Location="SOPE.ListQuery.dll">
            <SafeControls>
                <SafeControl Assembly="SOPE.ListQuery, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5232633792b38efa"
                             Namespace="SOPE.ListQuery"
                             TypeName="*"
                             Safe="True"/>
            </SafeControls>
        </Assembly>
    </Assemblies>
</Solution>

 

 

I hope I have saved some one a little time 😉

My First Blog

Hi There,

I would like to introduce myself, my name is Trent Allday. I live in Melbourne Australia and have a pashion for IT, specifically programming.

This blog will be a repository for keeping notes, links on what I have learnt through project experiences and just general reflections. I hope some of this information maybe beneficial to you when your banging your head against the wall as i often do.

Happy reading!

Regards Trent.