Reputation: 411
I am attempting to make an asmx file (written in c#) which will receive a POST request from another service, in this case Trello. However I believe I am having trouble receiving a 'JSON payload'. Trello is creating the request so I don't know exactly what their code looks like. The code I am using to recieve the request is of the form:
[WebMethod]
public string TrelloCallback()
{
//connect to database
//do stuff
//return "OK"
}
However this fails immediately, even if my code only consists of "return OK". I have used Applications such as Postman (https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm?hl=en) and have successfully sent both post and get request to TrelloCallback using the url excample.com/excample2.asmx/TrelloCallback, however requests from Trello simply fail.
If anyone has any idea about what could be causing this problem, or has solutions for a workaround I would be very grateful.
p.s. The payload is of the form:
{
action: { ... }//Action (comment, move)
model: { ... }//Basic information
}
Upvotes: 3
Views: 1498
Reputation: 411
First, you have to make sure you have the line for ScriptService
namespace MyName
{
...
[ScriptService]
...
public class MyClass: MyWebService
{
...
Then you only need to read through the stream to get the Body
StreamReader reader = new StreamReader(Context.Request.InputStream);
Context.Request.InputStream.Position = 0;
String Body= reader.ReadToEnd().ToString();
Context.Request.XXX provides many useful messages for interoperating the request you received.
For example - Context.Request.Headers, Context.Request.RawUrl, and Context.Request.HttpMethod.
Upvotes: 4