WCF POST web service

M

mat

Hello,

New to WCF and I was wondering is anyone knows of a working (complete)
example of a WCF web service which implements HTTP POST?

I've attempted to create one - which I think works but want to make
sure. Then I can start implementing the data contact (XML document).

Also, does anyone know how to call these web services from the
browser? I need to make sure it can be called by more than just .Net.

Many thanks
 
A

Arne Vajhøj

mat said:
New to WCF and I was wondering is anyone knows of a working (complete)
example of a WCF web service which implements HTTP POST?

All SOAP and REST does.
Also, does anyone know how to call these web services from the
browser?

Very unpractical.
I need to make sure it can be called by more than just .Net.

Then try call it from a couple of languages: Java, Python, PHP etc..

Arne
 
J

James Parker

mat said:
Hello,

New to WCF and I was wondering is anyone knows of a working (complete)
example of a WCF web service which implements HTTP POST?

I've attempted to create one - which I think works but want to make
sure. Then I can start implementing the data contact (XML document).

Also, does anyone know how to call these web services from the
browser? I need to make sure it can be called by more than just .Net.

Many thanks

I use jquery to call the web service from the browser.

$.ajax({
type: "POST",
async: false,
url: "/Controls/WebServices/GeneralService.asmx/SaveNewPackage",
data: "{'name':'" + $("#txtPackageName").val() +
"','cost':'" + $("#txtPounds").val() + "." +
$("#txtPence").val() +
"','enabled':'" + $('#chkEnabled').is(':checked') +
"','renewalType':'" + $("#ddlRenewPeriod :selected").val() +
"','companyId':'" + $("#ddlCompany :selected").val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
},
error: function() {
jAlert('Unable save the new package.', 'System Error');
}
});

which calls the following method running within a webservice.

[WebMethod(EnableSession = true)]
[ScriptMethod]
public bool SaveNewPackage(string name, decimal cost, bool enabled, int
renewalType, int companyId)
{
try
{
var package = new Package
{
Name = name,
Cost = cost,
Enabled = enabled,
PackageRenewalPeriodTypeId = renewalType,
CompanyId = companyId,
CreatedBy = CommonHelper.CurrentUserId,
CreatedOn = DateTime.Now
};

new PackageComponentHelper().SavePackageComponent(package);
}
catch (Exception ex)
{
var exceptionManager =
ExceptionManagerFactory.GetExceptionManager();
// log the exception
exceptionManager.LogException(ExceptionManager.Severities.Warning,
ex,
"Error Whilst Saving New
Package");

return false;
}

return true;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top