0

I created a web method but when i go to the site and type for example http://mysite.com/services/Amounts/GetAmount it returns an error Internal Server Error 500. After investigating the issue in event logs etc,, it says GetAmount invalid method name. but i know the mame is fine

[WebMethod(EnableSession=true)]
public string GetAmount(Amounts amts)
{
    //some logic here to add to the database.
}

What are the possible issues that I have to look into when this type of error shows?, I checked all the references and everything is named properly "GetAmount".

John Saunders
  • 160,644
  • 26
  • 247
  • 397
user710502
  • 11,181
  • 29
  • 106
  • 161
  • Have you taken a close look at your web.config in the 'protocols' section? – Bryan Crosby Mar 30 '12 at 03:50
  • It is webservice or webmethod in code behind? if its webmethod in code behind you need to define the method as static. – Mutant Mar 30 '12 at 03:52
  • Try storing the return value in a variable and then displaying in a Listbox or something and when you making this call :http://mysite.com/services/Amounts/GetAmount .... why isn't the value amts not passed along or is provided in the call? May be thats y is it finding a mismatch with the signature of the method.Though i am not sure how you are implementing it in the client side :) – Milee Mar 30 '12 at 04:54
  • Also, have a look at this,might help a bit in your analysis :http://www.checkupdown.com/status/E500.html.So, I guess it is some kind of issue with your web method definition and not from the client application :) – Milee Mar 30 '12 at 04:56
  • This is the thing, there are other services like /Amounts/InsertProductAmount that works, like if you type that url it does not return the error it just says.. "out of array index" or something..but thats ok.. because i know that one works when actually someone is passing the JSON. I am using Visual Studio 2008 .Net Framework 3.5 – user710502 Mar 30 '12 at 05:59
  • Oh k.. are you deploying currently in the same machine? For both client and server? try adding the dll of your servce to your references and use that at client side in case you are want to deploy in some other machine.May be you are not running it in the localhost in case you are testing in the same machine. – Milee Mar 30 '12 at 06:25
  • Also,please reply with @username else we will not be notified. :) – Milee Mar 30 '12 at 06:30

1 Answers1

0

What are you trying to do here? You need to post more code and web.config. Which version of .NET you are using here? All this information may get you the better answer.

Firstly, your URL http://example.org/services/Amounts/GetAmount does not seems to be correct - there has to be .asmx somewhere unless you are using ASP.NET routing or some url rewriting.

Assuming that your routing/re-writing is indeed working correctly: in general, if its a normal SOAP Web Service then enable HTTP get -

<webServices>
    <protocols>
      <add name="HttpGet" />
      <add name="HttpPost" />
    </protocols>
</webServices>

If you are trying create a service callable from script (ScriptService) then for asmx service, you need to mark the method as ScriptService and you may need to adjust web.config based on your .NET version. Also you need to enable HTTP GET - for example,

[ScriptMethod(UseHttpGet = true)]
public string GetAmount(Amounts amts)

You may also need to adjust Response Format whether you want JSON or XML.

VinayC
  • 47,395
  • 5
  • 59
  • 72
  • This is the thing, there are other services like /Amounts/InsertProductAmount that works, like if you type that url it does not return the error it just says.. "out of array index" or something..but thats ok.. because i know that one works when actually someone is passing the JSON. I am using Visual Studio 2008 .Net Framework 3.5 – user710502 Mar 30 '12 at 05:58
  • @user710502, what are attributes applied to the methods that work against `GetAmount` method? Also check the code that does routing - there can be issue in that code! – VinayC Mar 30 '12 at 06:10