RangerMSP Account Search
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
namespace DemoRangerMSPAccountSearch
{
class Program
{
/*
* Instructions
*
* 1. Disable Authentication and SSL.
* 2. Add a Service Reference to the RangerMSP Service, name the reference RangerMSPService.
* The uri will generally be http://localhost:11111/RangerMSP.
* 3. With new release you may have to update the Service Reference.
*/
static void Main(string[] args)
{
RangerMSPService.AccountClient accountClient = new RangerMSPService.AccountClient();
(accountClient.ChannelFactory.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
(accountClient.ChannelFactory.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
(accountClient.ChannelFactory.Endpoint.Binding as BasicHttpBinding).ReceiveTimeout = new TimeSpan(0, 10, 0);
RangerMSPService.Select select = new RangerMSPService.Select
{
Link = "and",
RecordLimit = 0,
Criterias = new RangerMSPService.Criteria[1]
{
new RangerMSPService.Criteria
{
Field = "",
Operation = "opLike",
Value = ""
}
}
};
select.Criterias[0].Field = "CompanyName";
select.Criterias[0].Value = "D" + "%";
select.RecordLimit = 10; // Define max number of records to retrieve.
RangerMSPService.AccountRecord[] accountRecord = accountClient.Select(select);
foreach (RangerMSPService.AccountRecord record in accountRecord)
{
string companyName = record.CompanyName;
Console.WriteLine($"companyName: {companyName}");
}
Console.WriteLine("Press enter to continue.");
Console.ReadLine();
}
}
}
# Instructions
#
# 1. Disable Authentication and SSL
$Uri = 'http://localhost:11111/RangerMSP'
$Xml = @'
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
{0}
</soap:Body>
</soap:Envelope>
'@
$Body = @'
<Select>
<Select xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Criterias>
<Criteria>
<Field>CompanyName</Field>
<Operation>opLike</Operation>
<Value>D%</Value>
</Criteria>
</Criterias>
<RecordLimit>10</RecordLimit>
<Link>and</Link>
</Select>
</Select>
'@
$result = (Invoke-WebRequest -UseBasicParsing -Body ($Xml -f $Body) `
-method POST –contentType "text/xml" -Uri $Uri -TimeoutSec 100 -Headers @{"SOAPAction"="urn:IAccount/Select"})
$StringWriter = New-Object System.IO.StringWriter
$XmlWriter = New-Object System.XMl.XmlTextWriter $StringWriter
$xmlWriter.Formatting = "indented"
$xmlWriter.Indentation = 4
([xml]($result.content)).WriteContentTo($XmlWriter)
$XmlWriter.Flush()
$StringWriter.Flush()
Write-Output $StringWriter.ToString()
Write-Output $result.ToString()
The Select statements for selecting Accounts and other RangerMSP objects can be more complex than a single criteria. The select statement below has three criteria to select based on CompanyName, AccountType and Status
Select selectAccount = new Select
{
Link = "and",
RecordLimit = recordLimit,
Criterias = new Criteria[3]
{
new Criteria
{
Field = "CompanyName",
Operation = "opLike",
Value = M%
},
new Criteria
{
Field = "AccountType",
Operation = "opEqual",
Value = "1"
},
new Criteria
{
Field = "Status",
Operation = "opEqual",
Value = "Active"
}
}
};