I have no previous knowledge of connecting to a web service using JSON and I haven't been able to find any examples online that clearly explain how I would go about connecting using authentication.

I have the following documentation:

Credential (type: Credential) - An object used to authenticate the client
MMCode (type: String)
RegYear (type: Int32)

The Credential object is made up of:

Username (type: String/nvarchar – length between 5 and 50 characters)
Password (type: String/nvarchar – length between 5 and 50 characters)
ClientIdentifier (type: String)

How do I go about doing this?

The one thing I failed to mention is the method which is SearchByMMCode

Your JSON object should probably look something like this:

var postData = {
  "Credential": {
    "Username" : "user",
    "Password" : "pass",
    "ClientIdentifier" : "ident"
  },
  "MMCode" : "code",
  "RegYear" : 2012
};

Hi pritaeas

I have the variable setup like that at the moment but I'm not having any luck getting a proper response.

Here's my code as it stands

<script type="text/javascript">
var usernameString = 'username';
var passwordString = 'pass';


    var postdata = { 
        "Credentials": {
            "Username": usernameString,
            "Password": passwordString,
            "ClientIdentifier": "string"
        },
        "MMCode" : "code",
        "RegYear" : 2012
    }


    //alert(postdata);
    var jsonstr = JSON.stringify(postdata);
    alert(jsonstr);

    var xmlhttp = new XMLHttpRequest;
    xmlhttp.onreadystatechange = function()
    {
        if(xmlhttp.readyState ==4)
        {

            alert(xmlhttp.responseText);

        }

    }
    serverURL = "serverUrl?wsdl";
    //alert(serverURL);
    xmlhttp.open("GET",serverURL,true);
    xmlhttp.send(null);
</script>

The responseText just comes back blank.

Usually you don't post to the ?wsdl URL. That is just for retrieving the possible functions. Are you sure you need to send by GET?

If you use SoapUI, do you get a response? Personally, that would be the first thing I'd try before starting to code.

I've never heard of SoapUI until now. I'll download it and feed back once I know more.

SoapUI is a very good software, i've used it alot for testing purposes!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.