asp.net api service.svc query length problems - c#

Hello I got a service that is made for sending html mails, it will be called from a method "SendMail(data) about 1500 characters.
I access the service though JQuery with AJAX call and JSON:
var data = encodeURIComponent(JSON.stringify(dataArray));
$.ajax({
type: "GET",
url: "http://localhost:53334/Service.svc/SendMail?data=" + data,
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function () {
alert("Reklamationen er blevet sendt!");
},
error: function (err) {
alert("Kunne ikke sende reklamation! Der opstod en fejl.");
}
});
I got alot of fields and if I fill everything out it gives a 404 not found response but then if I leave some random fields empty it gets to the API and executes the method it should? So I think its about the data size. I have tried many settings in webconfig but i havent managed to find a solution.
I hope there will be someone who can help me.

You should really be using POST as indicated by Tikkes. Semantically you aren't requesting a resource from the server, so GET doesn't make sense. Also, as noted here there is a maximum length that is enforced for Urls which is what GET uses to pass params(as you can see in your code as well). POST on the other hand uses the request body to send its data. Also, as noted here POST and GET sizes are usually configurable on the server, but POST is generally much larger(2KB vs 10MB defaults) as stated in one of the answers. Hope this helps.

Related

Error thrown while performing ajax call to web api

I have the following basic code. I tried to debug this code but the javascript is very painful to debug, and I do not know where it is failing:
jQuery.support.cors = true;
var packet = {
Image: imageAsString,
PhnType: phoneType,
PhnMdl: phoneManufacturer
};
$.ajax({
url: "https://molecheckerservices2.azurewebsites.net/api/Testing/SubmitTestingData",
type: "POST",
dataType: "json",
data: JSON.stringify({ packet }),
success: function(data, textStatus, xhr) {
alert('yes');
window.localStorage.setItem("dataObject", JSON.stringify(data));
window.location = "results.html";
},
error: function (xhr, textStatus, errorThrown) {
alert('no');
window.localStorage.setItem("dataObject", JSON.stringify([.33, .33, .33]));
window.location = "results.html";
}
it gives me back an alert no, which corresponds with a failure. Additionally as I debug I see in my Javascript console that the error:
Failed to load resource: the server responded with a status of 400 (Bad Request)
Pops up. I tried to look up what this mean but I would be incredibly grateful for any problem specific advice!
Open up Fiddler and manually POST to your endpoint. If you do that, you will see the same error message I saw:
{"message":"No API version was specified in the request, this request needs to specify a ZUMO-API-VERSION of '2.0.0'. For more information and supported clients see: http://go.microsoft.com/fwlink/?LinkId=690568#2.0.0"}
It has a handy-dandy link in there for you. Also, here is a SO answer that possibly applies to you.
I did add the header mentioned above, resent the request and I received that sweet 200 response from your service, so I'm pretty sure that's your issue.
P.S. If you don't want random strangers inserting data into your app like I just did, you should secure your service or at least obfuscate the URL when mentioning it in public.

How to view soap service data from my browser

I'm completely new to how soap services work, please correct me if my understanding is wrong. I would like to pass parameters and call a function from a soap service by typing in a url on my browser (Chrome) and then would like to see the results. I tried searching and following the information from here, but I'm not sure what I'm doing wrong. I have tried the following variations:
http://<servername>/apppath/MyService.asmx?op=GetData?loc=01&status=OPEN
http://<servername>/apppath/MyService.asmx/GetData?loc=01&status=OPEN
This is what I get when I go to the url.
http:/<servername>/apppath/MyService.asmx?op=GetData?
Please help.
Maybe you are requesting wrong urls? If you have .asmx in your application - you should be able to see the description page on the url
http://{servername}/{apppath}/MyService.asmx
Of course you should replace {servername} the {apppath} with your values.
You have to send an HTTP POST request in order to call your web service GetData.
Your JS code should be something like:
//url should be MyService.asmx/GetData
function callWS(url) {
var loc = "01";
var status = "OPEN";
var options = { error: function(msg) { alert(msg.d); },
type: "POST", url: "webmethods.aspx/UpdatePage",
data: JSON.stringify({ loc: loc, status: status }),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function(response) { alert(response); }
};
$.ajax(options);
}
So the error was my understanding of SOAP and host to use Postman. In short, I wasn't able to accomplish a SOAP request through the browser. Also, the picture supplied, it showed I was missing 2 things. 1) The SoapAction 2) The parameters were not supplied in the url but rather in the <soap:Body> tag. These were supplied in the POST and I was able to view my results in Postman

Dojo 1.8 web service call fails with status: 500 error code

dojo.xhrPost({
url: "Default.aspx/TestMethod",
handleAs: "json",
contentType: "application/json",
postData: dojo.toJson({ }),
load: function (result) {
debugger;
},
error: function (err) {
debugger;
}
});
That is the script I use to make a request to a WebMethod that is exposed in Default.aspx. The method is called TestMethod.
The error that I get is:
Unable to load Default.aspx/TestMethod status: 500
If you need any additional information please let me know.
*Note : I can call the method from the server side and it returns the results as intended.
I've been there. :(
Usually it is a problem with the format of the data that you are passing in. For instance, if your WebMethod has a parameter that is an int and you are passing a string, you will get a failure like this.
I would use a tool like Fiddler http://www.fiddler2.com/fiddler2/ to see what you are sending to the method.
Also turn on what ever server side logging and tracing that you have and use it. One source that is useful for 500 errors (which tend to happen before "your" server code is reached) is Asp.net health monitoring.
There is more info about setting that up and using it at http://msdn.microsoft.com/en-us/library/bb398933(v=vs.100).aspx

Jquery Ajax multi user request

I am very new into ajax and i am having a strange problem, I have created an asp.net website that have a web service within the project I am calling this web service by following ajax code:
$.ajax({
type: "POST",
url: pageUrl + "/PassData",
data: JSON.stringify({ aos_code: code }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccessCall
});
the c# code is not very complicated, basically it will get the code and call the stored procedure and return some value:
[WebMethod(EnableSession = true)]
public string[] PassData(string aos_code)
{
// calling the database and returning some data
return data;
}
And it works fine; the problem is that if two different users accessing the application in the two different computers and let say they clicking a button at the same time to call the server side function via Ajax, it will return the “500 internal server error”.
I am not sure how exactly Ajax work, is request are belong to same session or all user requesting a single function?
Hope it makes sense, and I would really do appreciate for the clarification and help.
Regards,
Error 500 indicates that something went wrong on the server side. Check your console (firebug or similar) to see what exactly happened and try to fix it. Ajax has nothing to do with it, it is simply as if two users visited the same page at the same time.

500 - Internal server error. how i can solve it in asp.net MVC 3 on server?

I deployed a mvc 3 project.
The server gave an error 500 - Internal server error. Nothing else.
How can I get more detail about it. How can I know the reason behind it, because there is nothing going wrong in my code in my development machine.
Since I just have FTP access, is there a way for me to create a log and get all the information about the error in detail.
are their any possible thing i can do that i can see the error in my browser. no problem because i deploy on testing domain.
You will get a 500 error if the web.config xml is invalid. Find out if is invalid by opening IIS Manager, and for the site double click on one of the features (Authorization, HTTP Redirect). If the xml is invalid, it will display a message box with an error and a line number.
If the web config is ok, configure customErrors so you can the errors.
http://msdn.microsoft.com/en-us/library/h0hfz6fc(v=vs.100).aspx
This might display some more detailed information.
Please make sure is ASP.Net MVC installed on the server? or Is the correct version of IIS installed on the server?
Check that the data is out of ajax like data_.
var data_ = { indexNum: index };
$.ajax({
type: "POST",
url: "/Home/ExamsById",
data: data_,
dataType: 'json',
success: function (response) {
$(".cont-exams").slideToggle();
}
});
Check that the data is out of ajax like data_.
var data_ = { indexNum: index };
$.ajax({
type: "POST",
url: "/Home/ExamsById",
data: data_,
dataType: 'json',
success: function (response) {
$(".cont-exams").slideToggle();
}
});

Categories

Resources