Interactive Address Validation with Web Services (.net)
This example is a
VERY simplistic integration example for integrating an application with DuoShare. You can get more information about DuoShare and request
an account through our website or contact our Sales Department at 214-691-4884. You will not be able to run this example without an account
to connect to DuoShare's service.
This example was written in Visual Studio 2005 using the .Net framework 2.0. You will also need to download WSE 3 from Microsoft at the link below.
http://msdn.microsoft.com/webservices/webservices/building/wse/default.aspx
Reference documentation for the record classes is available here.
First, obtain a developer login and password from DuoShare and then get the PostML wsdl at this link:
https://duoshare.com/dsWS/services/PostML/wsdl
Save this wsdl on your computer and run WseWsdl3, which should be located in your WSE 3.0 installation directory:
WseWsdl3.exe /type:webClient /nologo /namespace:DuoShare.Webservices postML.wsdl
This will generate PostMLService.cs
Create a new console application in Visual Studio. Name it Interactive Test
Add the newly generated PostMLService.cs file to your project.
Right click References, find and add Microsoft.Web.Services3, System.Web.Services, and System.Security to the project.
In Program.cs, add the following code:
using System.Security;
using System.Net;
using System.Net.Security;
using DuoShare.Webservices;
using Microsoft.Web.Services3.Security.Tokens;
using Microsoft.Web.Services3.Security;
using Microsoft.Web.Services3.Design;
In your main method, create an instance of postML:
PostMLService service = new PostMLService()
Add this next bit of code right after the PostML initialization in Main:
string username = "YourUserName";
string password = "YourPassword";
long? customerPk = null; //This should be your account's customer primary key... it won't work without it
UsernameToken token = new UsernameToken(username, password, PasswordOption.SendPlainText);
Policy policy = new Policy();
policy.Assertions.Add(new UsernameOverTransportAssertion());
service.SetClientCredential(token);
service.SetPolicy(policy);
That concludes the security portion of this example. Now it's time to validate an address.
//You can remove the vowels for most city and street names to save
//keystrokes when validating an address
WsPostalinputRecord record = new WsPostalinputRecord();
record.deliveryaddressline1Input = "10401 mllr rd #150";
record.lastlineinput = "dlls tx 75238";
record.customerpk = customerPk;
WsPostaloutputRecord output = service.validateInteractive(record);
Console.WriteLine (output.deliveryaddressline1Answer);
Console.WriteLine(output.lastlineanswer);
Console.Read();
The entirety of Program.cs is below for completeness.
using System.Security;
using System.Net;
using System.Net.Security;
using DuoShare.Webservices;
using Microsoft.Web.Services3.Security.Tokens;
using Microsoft.Web.Services3.Security;
using Microsoft.Web.Services3.Design;
namespace InteractiveTest
{
static class Program
{
static void Main()
{
//Initialize PostmL
PostMLService service = new PostMLService();
//Your username and password
string username = "YourUserName";
string password = "YourPassword";
long? customerPk = null; //This should be your account's customer primary key... it won't work without it
//Username token for webservices
UsernameToken token = new UsernameToken(username, password, PasswordOption.SendPlainText);
Policy policy = new Policy();
policy.Assertions.Add(new UsernameOverTransportAssertion());
service.SetClientCredential(token);
service.SetPolicy(policy);
//You can remove the vowels for most city and street names to save
//keystrokes when validating an address
WsPostalinputRecord record = new WsPostalinputRecord();
record.deliveryaddressline1Input = "10401 mllr rd #150";
record.lastlineinput = "dlls tx 75238"#59;
record.customerpk = customerPk;
WsPostaloutputRecord output = service.validateInteractive(record);
Console.WriteLine(output.deliveryaddressline1Answer);
Console.WriteLine(output.lastlineanswer);
ConsoleRead();
}
|