I built a custom javascript converter, but it is not being called when I call my webservice.
namespace LoanPal.WebServices.Converters { public class ContactConverter : JavaScriptConverter { public ContactConverter() {
}
public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
{
if ((dictionary != null) && (type == typeof(Contact)))
{
Contact contact = new Contact();
contact.Id = serializer.ConvertToType<int>(dictionary["Id"]);
return contact;
}
return null;
}
public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer)
{
Contact contact = obj as Contact;
Dictionary<string, object> result = new Dictionary<string, object>();
if (contact != null)
{
result.Add("Id", contact.Id);
return result;
}
return result;
}
public override IEnumerable<Type> SupportedTypes
{
get { return new List<Type>(new Type[] { typeof(Contact) }); }
}
}
}
I registered it in the web.config
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="10000">
<converters>
<add name="ContactConverter" type="LoanPal.WebServices.Converters.ContactConverter, App_Code" />
</converters>
</jsonSerialization>
</webServices>
</scripting>
</system.web.extensions>
Then I am making a WCF call but it isnt hitting it with a breakpoint.
[OperationContract]
[PrincipalPermission(SecurityAction.Assert, Role = "LoanOfficer")]
[WebGet(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public ContactProxy SaveContact(ContactProxy contactProxy)
{
return contactProxy;
}
Any ideas?