NServiceBus Request/Response AgumentNullException: Parameter name: session - asp.net-web-api

I have a .Net Web API app that is making a Request/Response type call using NServiceBus.
This is the code that makes the call:
var postOrderResponse = await endpoint
.Request<PostOnlineSalesHeaderResponse>(message, cancellationTokenSource.Token)
.ConfigureAwait(false);
And it fails with this exception:
System.ArgumentNullException: Value cannot be null.
Parameter name: session
at NServiceBus.RequestResponseExtensions.d__3`1.MoveNext() in C:\BuildAgent\work\5008c1ef0abd347d\src\NServiceBus.Callbacks\RequestResponseExtensions.cs:line 93
What am I missing?

Uhg nevermind...I was being a dumbass....I hadn't correctly initialized the endpoint on which I was making the call.

Related

Serverless WebSocket route responses

I am using serverless to create a WebSocket service, for which I am able to successfully trigger my WebSocket routes locally, using serverless-offline and for the deployed service.
The issue I am having now is responding to those WS events.
I am able to use AWS.ApiGatewayManagementApi.postToConnection to respond to my local WebSocket events, though I cannot seem to get the return value of my handler to actually send a WebSocket event in response, as these serverless-offline docs and these AWS docs suggest.
The serverless.yml route:
ws-custom:
handler: handler.wsCustom
events:
- websocket:
route: custom
routeResponseSelectionExpression: $default
The handler:
module.exports.wsCustom = async (event) => {
const body = JSON.parse(event.body);
console.log('WebSocket `custom` event!', event);
return {
statusCode: 200,
body: JSON.stringify({ message: `Hello, ${body.name}!` }),
};
}
Invoking the function in my browser JavaScript:
ws.send(JSON.stringify({ 'action': 'custom', 'name': 'kevbot' }));
The result is that my serverless-offline logs (or CloudWatch in the case of the deployed project) will create an event with the log successfully, but my client will receive no events in response.
Does anyone know how I can do this with the return value of the handler?
EDIT:
The problem seems to exist within my serverless-offline setup. I will attempt to get it working locally and will create an issue necessary.
An important point to note when using WebSocket APIs and trying to return a response from your integration back to the client, as mentioned in this doc:
For a route that is configured to use AWS_PROXY or LAMBDA_PROXY integration, communication is one-way, and API Gateway will not pass the backend response through to the route response automatically. For example, in the case of LAMBDA_PROXY integration, the body that the Lambda function returns will not be returned to the client. If you want the client to receive integration responses, you must define a route response to make two-way communication possible.
So, if you are using a proxy integration, then you cannot return a response back to the client. You would have to use the AWS.ApiGatewayManagementApi.postToConnection method to communicate any data.
Alternatively, if you are using a non-proxy integration, then you can set up a route response for your integration.

API Gateway WebSocket API postConnection timeout

I'm trying to set up a WebSocket API on API Gateway. I'm following the basic tutorial, and I have everything up and running -> Routes for $connect, $disconnect, "test", $default. I am able to connect to the API, store the connectionId in Redis, and retrieve it when accessing from the test route.
The problem is when I try to send back a message from my lambda (single lambda handling all routes). I'm using the following code
const apigwManagementApi = new AWS.ApiGatewayManagementApi({
apiVersion: '2018-11-29',
endpoint: `https://${event.requestContext.domainName}/${event.requestContext.stage}`
});
Then I call
await apigwManagementApi.postToConnection({
ConnectionId: connectionId,
Data: `Echo: ${data}`
}).promise()
This is only called on the "test" route.
All of this is as per their guide. I had to add a patch to be able to make postConnection work, again, as per their tutorial. The problem is when the above method is called I get a Internal Server Error message from the API Gateway and the lambda times out after 3 seconds.
There is very little info on this method. I'm not sure what is causing the internal server error. I have checked the endpoint and the connectionId, both are correct.
What am I doing wrong? Any suggestions?
So the problem wasn't the actual lambda but the fact that it wasn't set up in a VPC that had access to the Internet. So if you're lambda has VPC enabled, make sure you it has a NAT gateway and Internet gateway set up.

How to return non 200 HTTP status codes with Serverless + OpenWhisk and behind IBM Cloud API Gateway?

I can't figure out how to return http status codes for functions behind an API GW. No matter what I return, it always comes back as a 200. I've tried statusCode and code to no avail.
I'm using the Serverless framework with the OpenWhisk plugin. I'm deploying to IBM Cloud.
Web Action response content type parameter must be set to http to manually configure the HTTP response. This value defaults to json which ignores returned headers and statusCode values.
In The Serverless Framework, this value is set in the event configuration section of your YAML.
functions:
my_function:
handler: index.main
events:
- http:
method: GET
path: /api/greeting
resp: http

Twilio client: Outbound call isn't showing agent/caller name in 'From' field on call logs

I'm making an outbound call from my Twilio client to make outbound web browser calls. The calls are successfuly made and are fine, but...
Unfortunately I'm unable to see the agent/client name in your logs. I am currently using the agent/client name of 'Andy' but in Twilio's call logs it's showing the 'From' field as anonymous.
I have made a few changes to the JavaScript SDK and have added the following ''//CLIENT NAME clientName: 'Andy'' in the 'params' variable but this hasn't made a difference and the from field is still showing up as Anonymous in Twilio's call logs when I make an outbound call using the browser client.
How do I make this work? :(
Here is my code:
// Bind button to make call
document.getElementById('button-call').onclick = function () {
// get the phone number to connect the call to
var params = {
//CLIENT NAME
clientName: 'Andy',
//PARAMETERS THAT WILL BE SENT THROUGH TO TWILIO
To: document.getElementById('customer-number').value,
//THIS IS CUSTOMER CALLER ID WE'RE PASSING TO THE OUTGOING TWIML AS THE CALLER ID TO USE FOR OUTGOING CALL
CallerID: document.getElementById('source-number').value
};
console.log('Calling ' + params.To + '...');
Twilio.Device.connect(params);
};
Twilio developer evangelist here.
The parameters you pass into Twilio.Device.connect are not recorded by Twilio, but they are sent on as parameters to the URL you set as your application URL.
Client names are actually only required for incoming calls that are routed to a client. If you were to setup a client for outgoing calls only you need not setup a name. As such, client names are not captured by Twilio in the call logs.
If you need to track which clients are making calls you can do so within your own application by reading the clientName that you set in Twilio.Device.connect from the webhook parameters and associating it with the CallSid (also available in the webhook parameters).

Is it possible to get value stored in session to Client App built using worklight?

I have stored value in session from worklight adapter by writing following piece of code :
var request = WL.Server.getClientRequest();
var session = request.getSession();
session.setAttribute("dataToExport", "Data To Return");
Is it possible to retrieve this value from client app using some worklight api or other way?
Instead of using WL.Server.getClientReuest, perhaps you can use WL.Client.addGlobalHeader in your client-side code.
WL.Client.addGlobalHeader
AddGlobalHeader(headerName, headerValue)
Adds an HTTP header to be used in server requests issued by
an IBM Worklight framework. The HTTP header is used in all requests
until removed by the WL.Client.removeGlobalHeader API call.
WL.Client.addGlobalHeader("MyCustomHeader","abcdefgh");

Resources