Function GetPO() As PurchaseOrder
' Create an instance of the service
Dim wsDynamicsGP As DynamicsGPClient = New DynamicsGPClient()
Dim oExistingPO As PurchaseOrder
Try
Dim companyKey As CompanyKey
Dim context As Context
Dim purchaseOrderKey As PurchaseTransactionKey
' Create a context with which to call the service
context = New Context()
' Specify which company to use (sample company)
companyKey = New CompanyKey()
companyKey.Id = (-1)
' Set up the context object
context.OrganizationKey = CType(companyKey, OrganizationKey)
' Create a purchase transaction key to identify the purchase order
purchaseOrderKey = New PurchaseTransactionKey
purchaseOrderKey.Id = "PO2076"
'retrieve an existing PO
oExistingPO = wsDynamicsGP.GetPurchaseOrderByKey(purchaseOrderKey, context)
Catch ex As System.ServiceModel.FaultException(Of System.ServiceModel.ExceptionDetail)
Throw ex
Catch ex As System.ServiceModel.FaultException
Throw ex
Catch ex As Exception
Throw ex
End Try
' Close the service
If wsDynamicsGP.State <> CommunicationState.Faulted Then
wsDynamicsGP.Close()
End If
Return oExistingPO
End Function