C# - Web Service API Design - Input Validation And Error Response?
Jan 1, 2011
This might be a silly question, how do you usually response to errors? Response with one error at a time or Response with multiple errors at a time, in a list record
Example
Invalid Email Address format
Invalid Phone number format
Invalid Password .etc...
Invalid API credentials
Lastly, my validation in my controller looks like this:
[Code]....
The validation works for both First and Last in that the Validation Message is properly displayed for the appropriate error. However, the input-validation-error class is not being set on the textbox.
How do I ensure that the input-validation-error class gets set on the textbox when the textbox is tied to a field in a nested class of the Model?
I'm about to design my Web service API, most of the functions of my API is basically very simular to my web application. Now the question is, should I create 1 single method and reuse them for both the web application and the web service api? (This seems to be the logical solution, however its very complicated; it's much easier to duplicate the method used by the web application, and keep both separate, ie one method for the web application and one method for the web service.)
1) REUSE: one main method and reuse them for both web application and web service application (I like this but it's complicated)
WebAppMethodX --uses--> COMMONFUNCTIONMETHOD_X APIMethodX ---uses----> COMMONFUNCTIONMETHOD_X ie Commonfunctionmethod_x contains reusable set of common features PRO: less code, less maintenance, less bugs. CON: very complicated
2) DUPLICATE: two methods, one method for the web application and one method for the web service.
WebAppMethodX APIMethodX PRO: simple CON: duplication = more code, more maintenance, more bugs!
I am calling an AJAX Enabled WCF Service from jscript code and I'd like to bind the results to a very simple template. I get the results by calling the service via its jscript proxy:
[Code].... In the OnComplete function the DataView is created:
[Code].... The template which the data is bound to is really simple.
[Code].... The XML response from the service is something like:
[Code]....
I get an error saying: 'Name' is undefined. I tried to bind Person.Name, ArrayOfPerson.Person.Name and several permutations without any luck. I'm sure I've been missing something here, and there should be an obvious answer.
I've tried to override error message when input incorrect data type in input field on HTML form.For example I have the model like this.
public class Person { public string FirstName {get;set;} public int Age {get;set;} }
For view, I put text input for Age to get it value.When type some string in Age text box like 'test' and press submit button. I got this error message ,The value 'xxx' is not valid for AgeHowever, I want to change this message and try many way. There 's nothing effect this message value.
I hv a master page nd 3 content pages...my contents of d page r located in the middle of the page...
I have some alert boxes in my page...like this,. response.write(<script>alert('Invalid input')</script>);....
wen the "response.write" is executed. . all my contents of the page are moving to left side of d page and the fonts getting bigger and font style is changed as well . .
Web service error response (code/message etc) would you store it in a database? or would you keep the error response in a method.By the time I'm done with this, there will be hundreds of error response, maybe in the future, thousands? (I dont know yet, depends how large this web service grows).EDIT: error response is the response returned back to the application via the web service, (not to be confused with error logging).
After going through few asp.net 2.0 books surfacially, I want to accomplish most of the task using c# code and Sql database.
1.we can access and update data using various ways like using sqldatasource code, data reader,command object,dataset,datatable etc.But which one to use in which situation?I am very confused.what do you prefer most,why?
2. How to code professional way? I mean how to separate code using different classes and how to link all togerther?
3.I want to design a webform for entering/editing user input using c# code and use presentation control like gridview and detailsview for viewing,paging and sorting only.Is this possible?
I am writing a program to measure the latency(response round trip time) for a web service. I need to have this at client side.
My initial plan is to store the time at which request is sent and then calculate the difference in time when we recieve a response from the web service. Is this the correct way to measure latency of web service. This has some overhead because of storing time and all. How can this be done?
Another option is to attach a timestamp with the SOAP request. But the server should return the timestamp. This will not be possible in case of third party web services.
I'm working on an application that has a large number of inputs for certain types (50 money inputs, 30 date inputs etc). I have been creating an CompareValidator for each one to make sure users are putting in the correct information but I am curious if there is an easier way to create the validation once and apply it to all desired inputs? Writing out 80 validators that do basically the same thing seems like a waste. Am I missing something that already does this in .NET or are there anything out there that can make validation easier?
Note: All validation needs to be done on both the client AND server side. I've read a little about ASP.NET MVC validation but unfortunately that won't be an option here.
I am making some change to my MVC app to allow user to modify their existing email address contained in the profile. I have 'email' and 'confirm email' fields both which load the existing email address when the user enters the edit page (both textboxes are loaded from the same database field). The issue I am having is that when the user edits the 'email' text field and forgets or enters a different address into the 'confirm' field, validation occurs and instead of retaining what the user entered it loads what's contained in the Model when it tried to save into both fields once again (to the user it would appear that validation should not have occurred). I would like validation to fire and retain what the user initially entered in the text boxes.
For example, if the original email address is [URL] and the user enters [URL] for the 'email' address and forgers or enters a different address into the 'confirm' field, validation fires and loads [URL] into both because that's what was captured during the attempted Save. I would like for [URL] to remain in the 'confirm' textbox, or if the user entered something that never matched that would remain.
How can I get around this but still have the existing email address load into both fields when the user initially enters the 'Edit' area?
Firstly - I'm not asking this question How to include a web service in MVC3? I know where the button is :-)
I'm trying to find an example of best practices of how to use the new DI / Common Service Locator framework in order to make web service calls (and code dependent on web service calls) testable. I've no experience of using NInject or the like - is that the way to go?
I'm working on a page that uses a master page. In the master page, I have a drop-down and when a value is selected I generate an evenIn the web page, I have this statement "Addhandler Master.FilterChanged, AddressOf FilterChangedFromMasterPage"Everything works fine, and can edit the page as much as I want, but only with the Source view - because if I look at the design view, the entire MainContent section is reduced to this error; "Error Creating Control- MainContent / Object Reference not set to an instance of an object"But if I debug it locally, or FTP it to the server, it works just fine!
Web service API: I noticed that some companies like to pass integer as the "currency" amount, rather than pass a decimal data type with a decimal place ($ 100.29) is there a good reason why they choose integer for currency over decimal data type? Example, they do this
If I have a 3 layer web forms application that takes user input, I know I can validate that input using validation controls in the presentation layer. Should I also validate in the business and data layers as well to protect against SQL injection and also issues? What validations should go in each layer?
Another example would be passing a ID to return a record. Should the data layer ensure that the id is valid or should that happen in BLL / UI?
I've got an ASP.NET 4 site on which I want to allow people to put '<' in their password. However, .NET gets in the way by blocking (what it sees as) an attempt to put HTML in a form field. I know I can turn off input validation entirely, but I only want to turn it off for this one field. Does anyone know an easy way to do that?
We're doing a data integration project between a MS Sql Server database and a Microsoft CRM system (through its web services).
We're trying to build a "service" layer on top of the database. The design of our current solution is to use web services for CRUD, with xml being the format of data.
Views are created to consolidate related tables into one entity, and we query these views, using the "SELECT * FROM someview " + "For XML" to generated xml that will be returned from our web services.
For update we're trying to use the same approach - using SQL XML to map updates views, we have "instead of" triggers defined on top of these views, and in these "instead of" triggers we update the underlying tables.
The views/triggers are generated by tools so don't be too concerned with coding efficiency here...
what do you think if we use WCF data Provider to publish a enterprise data model (essentially DTOs) ? p.s., we don't have a BL layer for now, it's all in the stored procedures!!!
What is the easiest way to create a web service with XML response?Use WCF to create the web service? (seems really complicated)If i want to use WCF to create my web service, where do I start?
i want to"steal" the xml that the web service return to the client.how can i steal it ?what can i override ?i dont care if it will be also wcf...i just want to reach the result as xml after a specfic function start on the web serviceike there is no over ride to on serlize or something like that on the web service or any property on the client side ?