Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
does anyone know how to get a C# server application running in the console to display HTTP requests from a client as shown in this image?
http://imgur.com/filhZJZ
Thanks in advance!
If all you want to do is spin up an HTTP server and write out requests to the console, it should be pretty easy to accomplish using OWIN and Katana. Just install the following NuGet packages:
Microsoft.Owin.Hosting
Microsoft.Owin.Host.HttpListener
And use something along the lines of the following:
public static class Program
{
private const string Url = "http://localhost:8080/";
public static void Main()
{
using (WebApp.Start(Url, ConfigureApplication))
{
Console.WriteLine("Listening at {0}", Url);
Console.ReadLine();
}
}
private static void ConfigureApplication(IAppBuilder app)
{
app.Use((ctx, next) =>
{
Console.WriteLine(
"Request \"{0}\" from: {1}:{2}",
ctx.Request.Path,
ctx.Request.RemoteIpAddress,
ctx.Request.RemotePort);
return next();
});
}
}
You can of course tweak the output to your liking, having access to the full request and respose objects.
It will give you something like this:
You can do this using System.Diagnostics Tracing in Web API. On the asp.net website, you'll be able to read a detailed article.
Another possibility is turning on the IIS logging and then read the logfiles. I'm not quite sure how this is done, it's just what I do on apache2/linux, where you can tail -f log. I read something about powershell equivalents, but not for consoleapps, so I think I would stick with the Tracing.
Edit: After some looking around on SO I found this similar question with relevant answers:
How do I see the raw HTTP request that the HttpWebRequest class sends?
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I'm developing a RESTFUL web server that have some API REST used by android clients. It's the first time I've done API REST so i followed several guides to made it. Now when client make a GET request to get something, the server return the data in JSON, but not additionals information. Now that I'm making the android application I understand that this type of managment isn't good because i can't handle the errors like 401, 404, etc from application to show errors to the user (I use retrofit 2 with coroutines).
Can someone explain me the best method to make the responses from the server? I understand that I have to make a generic class like Response that have a Code and an Error_Message, and I have to extend this class for all my responses to add the data required from the client. But after that how I handle the response from my application? I can't make two different classes (one for errors and one for success responses).
Can someone help me?
The type of solution you propose, is not REST. A common practice in the past was to use only 200 success responses and POST everything. REST APIs by convention use the status codes to convey a meaning. You should also always think of error 500, because this will happen and your application should handle it.
You also might be interested in this: Microsoft best-practices api-design
I understand that this type of managment isn't good because i can't handle the errors like 401, 404, etc from application to show errors to the user
I don't see why you can't do that. There is perfectly good code to handle the requests.
#Override
public void onResponse(Call<YourModel> call, Response<YourModel> response) {
// All the 20x responses
if (response.isSuccessful()) {
} else if (response.code() == 401) {
} else {
}
}
You can also use an interceptor, if you are using OkHttp Check here for interceptor code
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Nuget used:
FireBaseAdmin v1.9.2
I'm trying to use firebase admin to send push notification to fcm.
I read the documentation but can't find any other good source to figure out how to use it properly.
I can't figure out where to add the serverkey and senderid.
I made a methode for sending push notifications.
Has anyone an example i could follow or any other documentation?
public override async Task<string> Send(List<String> tokens, string title, string body)
{
var message = Message()
{
Tokens = tokens,
Notification = new Notification()
{
Title = title,
Body = body
}
};
return await FirebaseMessaging.DefaultInstance.SendAsync(message).ConfigureAwait(false);
}
When i debug this code the response is null from SendAsync.
It might be because i didn't give it the serverkey and senderId but then i would expect an error like serverKeyNotFound.
Server key and sender ID parameters are not used in the Admin SDK. You just need to instantiate a FirebaseApp with some GoogleCredential as shown in https://firebase.google.com/docs/admin/setup.
On top of that your code seems to be syntactically incorrect. There's no Tokens property available in the Message class. You need MulticastMessage class for that. So I'd expect the above code to fail compilation.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have a project with azure notification hub using my student Microsoft account. I start Microsoft free account and create another hub and using the same APNS certification from the first project. Now I can receive notification when I send test message from azure portal but I can't receive any message when I send it from my app. Using the same app just change the connections string and hub name?
Using the same app just change the connections string and hub name?
Normally, we will not send the notification directly from the client app. We usually send the notification from the server backend. About how to send the notification from backend you could refer to this article.
If you still want to send the notification by codes from your app, you could refer to this article.
In this article, provide three way to send the notification.
Using C# codes, node.js, rest api. You could choose one way to achieve your requirement.
Here is C# codes demo.
1.Install Microsoft.Azure.NotificationHubs from Nuget package.
2.Use below codes to send the notification.
private static async void SendNotificationAsync()
{
NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString("<connection string with full access>", "<hub name>");
var alert = "{\"aps\":{\"alert\":\"Hello from .NET!\"}}";
await hub.SendAppleNativeNotificationAsync(alert);
}
Update:
I suggest you could check your connection string make sure the connection has the permission to send the notification.
Like this:
Then you could add this connection to the codes and set the right notification hub name in it.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm working now on my first bot with Microsoft Bot Framework, with ASP.NET.
After manually testing with the bot emulator, I'm looking for the best method to create automatic testing for the bot.
Considering two problems:
What is the best tool to automate such tests?
What is the best method to test a dialog that can return different answers to the same input?
One alternative is doing functional tests using DirectLine. The caveat is that the bot needs to be hosted but it's powerfull. Check out the AzureBot tests project to see how this works.
Another alternative, is doing what the BotFramework team is doing for some of their unit tests.
If you are using Dialogs, you can take a look to the EchoBot unit tests as they are simple to follow.
If you are using Chain, then take a look to how their are using the AssertScriptAsync method.
https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Tests/Microsoft.Bot.Builder.Tests/ChainTests.cs#L360
https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Tests/Microsoft.Bot.Builder.Tests/ChainTests.cs#L538
If you are looking for a way to mock up Luis Service, see this.
You may want to consider Selenium. Selenium is web browser automation software allowing you to write tests that programmatically read and write to the DOM of a web page. With a Selenium script you can:
login on any channel that provides a web client (and most of them do: WebChat, Telegram, Skype, Facebook, for example)
start a conversation with your bot
perform operations such as post a message to the chat and wait for a reply
test whether the reply is what you expected.
For automated testing of bots in Node.js, using ConsoleConnector in the same way as the tests in BotBuilder on GitHub works well, e.g. take a look at https://github.com/Microsoft/BotBuilder/blob/master/Node/core/tests/localization.js:
var assert = require('assert');
var builder = require('../');
describe('localization', function() {
this.timeout(5000);
it('should return localized prompt when found', function (done) {
var connector = new builder.ConsoleConnector();
var bot = new builder.UniversalBot(connector);
bot.dialog('/', function (session, args) {
session.send('id1');
});
bot.on('send', function (message) {
assert(message.text === 'index-en1');
done();
});
connector.processMessage('test');
});
...etc...
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
Does anyone know of any working gvoice api? I have found this project:
http://sourceforge.net/projects/gvoicedotnet/
but the login appears to no longer work since the url changed some months ago.
Does anyone have a good question for sending out text messages to users of my website?
I found one: SharpGoogleVoice.
https://bitbucket.org/jitbit/sharpgooglevoice/downloads
It only has text messaging support, but it works well and looks like good work.
Self-promotion: my API, SharpVoice, works/worked quite well (hasn't been tested in some time): https://github.com/descention/sharp-voice
Voice voiceConnection = new Voice(loginEmail, loginPassword);
string response = voiceConnection.SendSMS(smsToPhoneNumber, smsMsgBody);
What you need is an SMS gateway that will let you send out text messages via an API. A quick Google search yields Zeep Mobile, which lets developers send SMS text messages for free from their application.
Because it's free, there may very well be some restrictions, but if you architect your app correctly using a strategy or adapter pattern then you should be able to replace this module later on down the road with something more advanced based on the needs of your application.
The primary restriction on the free plan is that it's ad-supported. This may very well be ok for you during initial development and testing, but your production users will likely find this to be a significant problem in using your service. Zeep does have a paid plan that eliminates the ads, and there are of course countless other SMS gateways that have API's that you can use for a fee.
You can get send messages with Twilio.
An example using the C# helper library:
https://www.twilio.com/docs/libraries/csharp
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example
{
static void Main(string[] args)
{
// Find your Account Sid and Auth Token at twilio.com/user/account
string AccountSid = "YOUR_ACCOUNT_SID";
string AuthToken = "YOUR_AUTH_TOKEN";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var message = twilio.SendMessage(
"+15017250604", "+15558675309",
"Hey Kyle! Glad you asked this question.",
new string[] { "http://farm2.static.flickr.com/1075/1404618563_3ed9a44a3a.jpg" }
);
Console.WriteLine(message.Sid);
}
}