NetRegistry Reseller API with .Net 3.5 WCF Service

Background

Web services are not a new topic for web developers. Companies are slowly embracing this technology and are moving to incorporating them in their service offering. The beauty of web services is it makes available to developers the functionally and flexibility needed to come up with innovative tools and solutions.

NetRegistry have just release a beta version of a reseller API tool. This will enable their resellers to integrate their core “customer facing” services and portals directly with NetRegistry.

This post showcase the usage of this API within the ASP.NET environment and answers the question on how to use NetRegistry API within .net 3.5. It also utilises WCF (Windows Communication Foundation) to speedup development and creates a stable bridging infrastructure between NetRegistry and your .Net application.

Walkthrough

In this walkthrough, I will demonstrate how you can connect to the reseller API using .Net 3.5 WCF Services and implementing a simple call to the service API to check for a domain name availability. Using the NetRegistry API documentation you can extend this example to place an order for the domain and check the order status.

Consult your NetRegistry API documentation for more details.

The best way to effectively demonstrate the technique, I will build a simple web application that will perform a domain search and return the results of Available, Unavailable and Errors.

The source code for this walkthrough is available for download the the end of this post. You must have .net 3.5 SP1 installed and Visual Studio 2008.

Step #1: Create a web application and add a service reference

Create a new web application project in Visual Studio. once the project is created, right click on the application node in solution explorer and click “Add a Service Reference”

On the service dialog, copy and paste the service URL supplied by NetRegistry from documentation, then click “Go”. You will be prompted with security authentication request box, supply your API username and password. These details are NOT your console username and password. Contact NetRegistry about how to get these details.

after a successful authentication, you can go ahead and supply the namespace for this service. In this example, I used “NRService” and click “Ok”. This how the screen should look like.

At this stage Visual Studio would generated all the necessary default configuration and the service objects to send requests to the service. However, this is not enough to start sending requests to the API. By defaults, WCF has configured this API to use “basicHttpBinding”, which is not compatible with the NetRegistry API service.

Step #2: Modify WCF default configuration

WCF configuration resides in “web.config” file of the web application project within the tags:

<system.serviceModel>
</system.serviceModel>

replace the default configuration with these details:

<system.serviceModel>
<bindings>
<customBinding>
<binding name="IResellerAPIServiceSoapBinding">
<mtomMessageEncoding messageVersion="Soap11"/>
<httpsTransport manualAddressing="false"
maxBufferPoolSize="524288"
maxReceivedMessageSize="65536"
allowCookies="false"
authenticationScheme="Basic"
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536"
transferMode="Buffered"
useDefaultWebProxy="true"
requireClientCertificate="false"/>
</binding>
</customBinding>
</bindings>
<client>
<endpoint
address="https://theconsole.netregistry.com.au/external/services/ResellerAPIService/"
binding="customBinding"
bindingConfiguration="IResellerAPIServiceSoapBinding"
contract="NRService.ResellerAPIService"
name="ResellerAPIServicePort"/>
</client>
</system.serviceModel>

Also, Its very important to note that the address in “endpoint” has “https://”. Because for some reason WCF “Add a Service Reference” tool replaced “https://” with “http://”. If this is left unchecked the service call will error due to security channel not established.

Now our service is ready to be called and WCF will know how to handle the messages correctly.

Step #3: Authentication and Our first call

NetRegistry Reseller API requires that you authenticate with the API username and password on every call. This is achieved by suppling the credential details to the service object after you initiate it.

var service = new ResellerAPIServiceClient()
service.ChannelFactory.Credentials.UserName.UserName = "APIusername";
service.ChannelFactory.Credentials.UserName.Password = "APIpassword";

Let continue and make our call to search for a domain name availability.

resellerAPIResult results = service.domainLookup( &amp;quot;idpsolutions.com.au&amp;quot; );

This call will send the data to NetRegistry API to search for the domain name “idpsolutions.com.au”. The result of the search will be held in the “results” variable.

To see wither the domain is Available, Unavailable or if the result returned an error. I use the following:

if ( results.errors != null )
//call failed - display the error to the user
lblFailed.Text = string.Format( &amp;quot;Error: {0} - {1}&amp;quot;,
results.errors[0].errorCode,
results.errors[0].errorMsg );
if (results.fields.Length &amp;gt; 0)
{
//call success - display the results
lblResult.Text = string.Format(&amp;quot;{0} is {1}&amp;quot;,
results.fields[1].value,
results.fields[0].value);

//check the results to see if the domain available or not, change the colour of the label
this.lblResult.ForeColor = results.fields[0].value.ToLower()==&amp;quot;AVAILABLE&amp;quot;.ToLower()
? Color.Green
: Color.Black;
}

That’s it. Now you can follow the documentation provided by NetRegistry to use the functionality provided in the API to build your service using ASP.Net 3.5 with WCF.

Leave any question or comments if you need any further help.

Happy Coding …

Live Demo

http://domainlookup.sarmaad.com

Subscribe

Subscribe to our e-mail newsletter to receive updates.

,

No comments yet.

Leave a Reply