Consuming Web Services

In the following, I will show how to consume web services in a few ways. For a more in-depth guide to better understanding how web services work, I recommend reading the following resources:

What prompted me to write this is that I was tasked to connect to BPLogix Web Services and I had no idea how to do that because up until this point everything I have done had been with REST. BPLogix documentation wasn't much help to me since I was not familiar with Windows Communication Foundation and Web Services. The first step was to understand what exactly those ASMX files were and what WCF was.

What is the Difference between ASMX and Windows Communication Foundation (WCF)

ASMX files are ASP.net Web Services and is the primary web service technology in .NET 1.0 and 2.0.

  • Only can be hosted in IIS
  • Uses SOAP
  • Only uses HTTP to communicate
  • Very simple to implement. Just add your file, compile, and it's there.

WCF is a unified framework for building service-oriented applications that provides more flexibility to the developer as well as greater security

  • Be Host
  • Also uses SOAP, but can use others
  • Can use HTTP, TCP, MSMQ, or NamedPipes
  • More configuration is needed to get this to properly work -- binding, discover ability, adding reference, updating configs, etc. It's not terrible, but I can understand where it might be a bit overwhelming if you're new.

Examples

ASP.Net

To get a better idea of how Web Services work, it would be a good idea to follow Micorsoft's Get Started Tutorial

The quickest way to get something up and running is to follow the Create Client tutorial. This does not need to be a part of a solution, but on its own.

svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://instance.bplogix.net/Services/wsAdmin.asmx?WDSL
svcutil.exe /language:vb /out:generatedProxy.vb /config:app.config http://instance.bplogix.net/Services/wsAdmin.asmx?WDSL

After the app.config and generatedProxy.vb have been generated, add the generatedProxy.vb to the solution.

Remember to add the necessary reference to the project. You will need to add the System.ServiceModel and System.Runtime.Serialization references.

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BPLogixWCFClient.wsAdminSoapClient;

namespace BPLogixWCFClient
{
	class Program
	{
		static voic main(string[])
		{
			wsAdminSoapClient client = new wsAdminSoapClient("wsAdminSoap");
			bpSoapHeader soapHeader = new SoapHeader();
			bool result;

			result = client.Authenticate(soapHeader, "user", "password");

			Console.WriteLine("Soap Header: {0}", soapHeader.ToString());
			Console.WriteLine("Result: {0}", result);

			Console.WriteLine("\nPress  to Terminate the client.");
			Console.ReadLine();
			client.Close()
		}
	}
}

Module1.vb


Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports BPLogixWCFClient.wsAdminSoapClient

Module Module1
	
	Sub Main()
		Dim client As New wsAdminSoapClient("wsAdminSoap")
		Dim soapHeader As New SoapHeader()
		Dim result

		result = client.Authenticate(soapHeader, "user", "password")

		Console.WriteLine("Soap Header: " & soapHeader.ToString)
		Console.WriteLine("Result: " & result)

		Console.WriteLine("\nPress  to Terminate the client.")
		Console.ReadLine()
		client.Close()
	End Sub
	
End Module

The using BPLogixWCFClient.wsAdminSoapClient and Imports BPLogixWCFClient.wsAdminSoapClient depend on two things. The first is the name of your project/solution, and the second is which WDSL you retrieved when ran the svcutil.exe command. In my example I used wsAdmin and had I used wsWorkflow, for example, then we'd use wsWorkflowSoapClient as the client and pass in wsWorkflowSoap as the parameter.

PHP

<?php
$client = new SOAPClient('http://instance.bplogix.net/Services/wsAdmin.asmx?WSDL');
$params = array(
	'User' = 'user',
	'Password' => 'password'
);
$result = $client->Authenticate($params);
echo $result->AuthenticateResult();

For each function you call, there is a "Result" function, i.e Authenticate has AuthenticateResult, DiskInfo has DiskInfoResult, ServerInfo has ServerInfoResult, and so on.

JavaScript

Consuming Web Services in JavaScript is very similar to how you would in PHP.


var soap = require('soap')
var url = 'http://instance.bplogix.net/Services/wsAdmin.asmx?WSDL'
var args = {
User: 'user',
Password: 'password'
}

soap.createClient(url, function(err, client) {
	client.AuthenticateJson(args, function(err, result) {
		console.log(result)
	})
})

Resources & Links