1

I want to call an web api method, this is how my web api method looks like:

[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:

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.

1 Answer 1

1
  1. You have "api/XYZ/" prefixed in your client code, but I don't see it on your server code. I predict that you have it in your server configuration but if not you will see issues.

  2. You can only have one object with the [FromBody] tag in WebAPI, it's not clear how your trying to pass the MyClass object.

  3. Only simple objects, ints and strings, can be passed in the uri string so the MyClass object will not be transferred correctly.

I would recommend removing the MyClass object or creating a larger object that encapsulates your List<SomeType> andMyClass` and pass that in the body of the request with the [FromBody] decoration.

Here's more information on the topic

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.