<form id="frmCustomerS" method="post" action="CustomerWcfServiceTest.aspx">
<div>
<table>
<tr><td colspan="2"><b>Through Client Side SOAP/XML HTTP POST</b></td></tr>
<tr><td>Customer ID :</td><td><input name="ID" id="ID" type="text" value="12345" /> </td></tr>
<tr><td>Customer Name :</td><td><input name="Name" id="Name" type="text" value="Chris Clark" /> </td></tr>
<tr><td>Customer DOB (yyyy-mm-dd):</td><td><input name="DOB" id="DOB" type="text" value="1988-08-08"/> </td></tr>
<tr><td>Customer Address:</td><td><input name="Address" id="Address" type="text" value="unknown"/> </td></tr>
<tr>
<td><input type="button" name="btnGetCustomer" value="Get Customer" onclick="GetCustomerSOAP()" /></td>
<td><input type="button" name="btnAddCustomer" value="Add Customer" onclick="AddCustomerSOAP()" /></td>
</tr>
<tr>
<td><input type="button" name="btnUpdateCustomer" value="Update Customer" onclick="UpdateCustomerSOAP()" /></td>
<td><input type="button" name="btnDeleteCustomer" value="Delete Customer" onclick="DeleteCustomerSOAP()"/></td>
</tr>
<tr>
<td colspan="2"><input type="button" name="btnGetAllCustomers" value="Get All Customers" onclick="GetCustomersSOAP()"/></td>
</tr>
</table>
</div>
</form>
ipt type="text/javascript" language="javascript">
var urlToPost = "http://vishwa/ExampleService/CustomerService.svc/basic";
var fixedSoapAction = "http://wcfservices.vishwamohan.net/ICustomerService/";
var serviceNameSpace = "\"http://wcfservices.vishwamohan.net\"";
var d = new Date();
function getFullDate()
{
if (d.getDate()<10)
return "0" + d.getDate();
else
return d.getDate();
}
function getFullMonth()
{
if (d.getMonth()<10)
return "0" + parseInt(d.getMonth()+1);
else
return parseInt(d.getMonth()+1);
}
var curdate = d.getFullYear() + "-" + getFullMonth()+ "-" + getFullDate();
function GetCustomerSOAP()
{
var dataText = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body>";
dataText += " <GetCustomer xmlns=" + serviceNameSpace + ">";
dataText += " <ID>" + frmCustomerS.ID.value + "</ID>";
dataText += " </GetCustomer>";
dataText += " </s:Body></s:Envelope>";
alert(dataText);
var xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("POST", urlToPost,false);
xmlHttp.setRequestHeader("Content-Type", "text/xml");
xmlHttp.setRequestHeader("SOAPAction", fixedSoapAction +"GetCustomer");
xmlHttp.send(dataText);
alert(xmlHttp.responseText);
}
function GetCustomersSOAP()
{
var dataText = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body>";
dataText += " <GetCustomers xmlns=" + serviceNameSpace + ">";
dataText += " </GetCustomers>";
dataText += " </s:Body></s:Envelope>";
alert(dataText);
var xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("POST", urlToPost,false);
xmlHttp.setRequestHeader("Content-Type", "text/xml");
xmlHttp.setRequestHeader("SOAPAction", fixedSoapAction +"GetCustomers");
xmlHttp.send(dataText);
alert(xmlHttp.responseText);
}
function AddCustomerSOAP()
{
var dataText = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body>";
dataText += " <AddCustomer xmlns=" + serviceNameSpace + ">";
dataText += " <CustomerRecord xmlns:a=\"http://schemas.vishwamohan.net/2008/01/Customer\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
dataText += " <a:ID>0</a:ID><a:Name>" + frmCustomerS.Name.value + "</a:Name><a:DOB>" + frmCustomerS.DOB.value +"</a:DOB>" ;
dataText += " <a:Address>" + frmCustomerS.Address.value + "</a:Address>" ;
dataText += " <a:DateCreated>" + curdate + "</a:DateCreated><a:DateModified>" + curdate + "</a:DateModified>" ;
dataText += " </CustomerRecord></AddCustomer>"
dataText += " </s:Body></s:Envelope>";
alert(dataText);
var xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("POST", urlToPost,false);
xmlHttp.setRequestHeader("Content-Type", "text/xml");
xmlHttp.setRequestHeader("SOAPAction", fixedSoapAction +"AddCustomer");
xmlHttp.send(dataText);
alert(xmlHttp.responseText);
}
function UpdateCustomerSOAP()
{
var dataText = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body>";
dataText += " <UpdateCustomer xmlns=" + serviceNameSpace + ">";
dataText += " <CustomerRecord xmlns:a=\"http://schemas.vishwamohan.net/2008/01/Customer\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
dataText += " <a:ID>" + frmCustomerS.ID.value + "</a:ID><a:Name>" + frmCustomerS.Name.value + "</a:Name><a:DOB>" + frmCustomerS.DOB.value +"</a:DOB>" ;
dataText += " <a:Address>" + frmCustomerS.Address.value + "</a:Address>" ;
dataText += " <a:DateCreated>" + curdate + "</a:DateCreated><a:DateModified>" + curdate + "</a:DateModified>" ;
dataText += " </CustomerRecord></UpdateCustomer>"
dataText += " </s:Body></s:Envelope>";
alert(dataText);
var xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("POST", urlToPost,false);
xmlHttp.setRequestHeader("Content-Type", "text/xml");
xmlHttp.setRequestHeader("SOAPAction", fixedSoapAction +"UpdateCustomer");
xmlHttp.send(dataText);
alert(xmlHttp.responseText);
}
function DeleteCustomerSOAP()
{
var dataText = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body>";
dataText += " <DeleteCustomer xmlns=" + serviceNameSpace + ">";
dataText += " <ID>" + frmCustomerS.ID.value + "</ID>";
dataText += " </DeleteCustomer>";
dataText += " </s:Body></s:Envelope>";
alert(dataText);
var xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("POST", urlToPost,false);
xmlHttp.setRequestHeader("Content-Type", "text/xml");
xmlHttp.setRequestHeader("SOAPAction", fixedSoapAction +"DeleteCustomer");
xmlHttp.send(dataText);
alert(xmlHttp.responseText);
}
</script>