I have a SoapExtension that is intended to log all SOAP requests and responses. It works just fine for calls from an application using the MS Soap Toolkit (OnBase Workflow). But it doesn't work for calls made by $.ajax() on an html page. Here's an example:
$.ajax({
type: "POST",
url: url,
data: data,
contentType: "application/json; charset=utf-8",
dataType: "json"
});
It's calling an ASP.NET 3.5 WebService marked with WebService and ScriptService attributes:
[WebService(Namespace = XmlSerializationService.DefaultNamespace)]
[ScriptService]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class DepartmentAssigneeService : WebService
{
private readonly DepartmentAssigneeController _controller = new DepartmentAssigneeController();
/// <summary>
/// Fetches the role items.
/// </summary>
/// <returns></returns>
[WebMethod]
[SoapLog]
public ListItem[] FetchDepartmentItems()
{
return CreateListItems(_controller.FetchDepartments());
}
}
And here are the basics for the SoapExtension and SoapExtensionAttribute:
public class LoggingSoapExtension : SoapExtension, IDisposable { /*...*/ }
[AttributeUsage(AttributeTargets.Method)]
public sealed class SoapLogAttribute : SoapExtensionAttribute { /*...*/ }
Am I missing something that would allow LoggingSoapExtension to execute on $.ajax() requests?
Update
@Chris Brandsma
It might be because you are requesting Json results instead of XML via your web service (dataType: "json"). So the ScriptService attribute is being activated, but you are not sending SOAP messages.
That answers why the SoapExtension isn't working. Any suggestions for tracing with ScriptService? The only thing that comes to mind is a ScriptService base class that provides a method to log a request. But then I'd have to call that method in every WebMethod in every ScriptService WebService (I have quite a few). I'd like to use something as clean and simple as a SoapExtension attribute, if possible.