Click here to Skip to main content
15,898,792 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to call an WebApi Method,this is how my webapi method looks like:


C#
[HttpPost]
            [Route("PostMyService/updatedBy/{updatedByID}/myobjname")]
            public void PostTerminalService([FromBody]  List<SomeType> lstSomeObj, MyClass myobj, int updatedByID)
    {
    //Do Something
    }


this is how my client looks like:

C#
int loggedinuserid=1;
     List<Sometype> liTS = new List<SomeType>();
   MyClass myobj=new MyClass();
       var url = "api/XYZ/PostMyService/updatedBy/" + loggedinuserid + "/myobjname/" + myobj;
       HttpResponseMessage response = client1.PostAsJsonAsync(url, liTS).Result;


But the error/exception I am getting is:
HTTP Error 404.0 - Not Found
Most likely causes:
•The directory or file specified does not exist on the Web server.
•The URL contains a typographical error.
•A custom filter or module, such as URLScan, restricts access to the file.


Any idea how to resolve this?I am kind of hitting a wall on this.

thanks in advance.
Posted
Comments
Kornfeld Eliyahu Peter 23-Jun-14 9:08am    
Put some sniffer - lie Fiddler - to see what URL you really try to reach...
avishekrc 23-Jun-14 9:27am    
Requested URL
http://localhost:55581/api/XYZ/PostMyService/updatedBy/1/myobjname/ABC.WS.Enrollment.Client.Model.MyClass
Kornfeld Eliyahu Peter 23-Jun-14 9:29am    
And does it make you sense?
I think your path mapping should be something like this:
[Route("PostMyService/updatedBy/{updatedByID}/myobjname/{myobj}")]
avishekrc 23-Jun-14 9:53am    
same result.

1 solution

Update your api method with this
C#
[Route("PostMyService/updatedBy/{updatedByID:int}/myobjname/{myobj:MyClass }")]
   public List<sometype> PostTerminalService(int updatedByID,MyClass myobj)
    {
    //Do Something
    }
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900