Catch Soap response message c# .net - c#

I have a Service Reference to communicate with WCF.
Now I can send the message with a method to the server. *
But I can't catch the response message. The request is fine, because I can handle the message with Fiddler Classic, but i need to handle it with c#.
Here is my code:
ServiceReference1.PUPHAXWSPortTypeClient client = new ServiceReference1.PUPHAXWSPortTypeClient();
client.ClientCredentials.HttpDigest.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
client.ClientCredentials.HttpDigest.ClientCredential.UserName = "PUPHAX";
client.ClientCredentials.HttpDigest.ClientCredential.Password = "puphax";
await client.TABATCAsync("<ATC>N05BA%</ATC>"); //* this method
If i want to storage the data to a variable or ServiceReference1.TABATCResponse tABATCRequest i got an exception which is invalid UTF-8 bytes.
Sorry for my english, here is the service reference: http://neak.gov.hu//data/cms1030808/PUPHAXWS_v1.22.wsdl

Related

SSL TLS communication in c# with self signed certificate not working

I have a .pem certificate file which is used to communicate between two servers. For communication I have written a program in C# like this:
var client = new RestClient("https://aaaaa.com:1111");
client.ClientCertificates = new X509CertificateCollection();
client.ClientCertificates.Add(new X509Certificate(#"C:\Users\aaa\Desktop\bbb.pem"));
var request = new RestRequest("/qqq/www", Method.POST);
request.AddJsonBody(new { create = new { msgBdy="Test" } });
var response = client.Execute(request);
Console.WriteLine(response.StatusCode);
//The underlying connection was closed: An unexpected error occurred on a send.
When I post the request through SoapUI it goes through, but when I try to send it through Postman or the above C# program it doesn't.
Screenshot from wireshark is below:
The change cipher spec event is called for the successful API call but through postman and c# application this event is never called.
I have tried to do this as explained in this article as well https://www.codeproject.com/Articles/326574/An-Introduction-to-Mutual-SSL-Authentication but that also didn't work.
How can I fix this issue.

Fiddler exception different than C# exception

We contact an Azure webservice to send over certain information.
When I send the request from C#, the exception provides the stacktrace from the sending side.
When I send the request from Fiddler, the exception provides the stacktrace from the receiving side.
I want to get the receiving side stacktrace in the logging as it's more usefull. Any ideas on how to do this? To my knowledge Fiddler uses HttpRequest as does C#
Code in C#:
HttpWebRequest r = (HttpWebRequest)WebRequest.Create(Adrewss);
...
HttpWebResponse response = (HttpWebResponse)r.GetResponse();
catch (Exception ex)
{
logEntry.Details = ex.ToString();
Let me know if more info is needed!
So C# ex =
500) Internal Server Error.
at System.Net.HttpWebRequest.GetResponse()
Fiddler ex:
{"Post":"System.NullReferenceException: Object reference not set to an instance of an object.\r\n at Test.Gateway.Models.Process.Transformer.GetTypeCode(String Type)\r\n etc
Fiddler doesn't use HTTPWebRequest at all, it talks to a raw socket. I'm guessing you're showing the raw text from the Response's body in Fiddler, while you're relying upon the exception (rather than the response body text) in your .NET code.

How to inject Http Parser into OWIN Self host server

I have http clients that are sending "POST" requests with no contents which cause the selfhost server to throw http 411 error , the http clients are for customers that it is not a solution to modify them , so the only way to modify my server to not throw this error when "POST" request arrive without content .
it seem it is happening in the low level , no attribute or filter or even app.Use worked to catch the request before the error get thrown
it mostly happening at the next level when TCP content get converted to HTTP request.
So basically I am looking for the point when before the server parse the TCP contents into HTTP request
static void Main(string[] args)
{
var baseAddress = new Uri("http://localhost:8073");
var config = new HttpSelfHostConfiguration(baseAddress);
config.Routes.MapHttpRoute("default", "{controller}");
using (var svr = new HttpSelfHostServer(config))
{
svr.OpenAsync().Wait();
Console.WriteLine("Press Enter to quit.");
Console.ReadLine();
}
}
It turned out the HTTP parser is not inject-able, it is kind of limitation in my openion to any http server , as the trip of data from TCP client until it get converted to HTTP request is black boxed at least in OWIN self host server

Telegram C# example send message

I can't find an example of sending message by telegram protocol from C#. I tried to use this but failed.
Can you give me any examples?
TLSharp is basic implementation of Telegram API on C#. See it here https://github.com/sochix/TLSharp
You can use the WTelegramClient library to connect to Telegram Client API protocol (as a user, not a bot)
The library is very complete but also very easy to use. Follow the README on GitHub for an easy introduction.
To send a message to someone can be as simple as:
using TL;
using var client = new WTelegram.Client(); // or Client(Environment.GetEnvironmentVariable)
await client.LoginUserIfNeeded();
var result = await client.Contacts_ResolveUsername("USERNAME");
await client.SendMessageAsync(result.User, "Hello");
//or by phone number:
//var result = await client.Contacts_ImportContacts(new[] { new InputPhoneContact { phone = "+PHONENUMBER" } });
//client.SendMessageAsync(result.users[result.imported[0].user_id], "Hello");
For my bot I use Telegram.Bot nuget package. Full sample code is here.
Here is example of sending message in reply to incoming message.
// create bot instance
var bot = new TelegramBotClient("YourApiToken");
// test your api configured correctly
var me = await bot.GetMeAsync();
Console.WriteLine($"{me.Username} started");
// start listening for incoming messages
while (true)
{
//get incoming messages
var updates = await bot.GetUpdatesAsync(offset);
foreach (var update in updates)
{
// send response to incoming message
await bot.SendTextMessageAsync(message.Chat.Id,"The Matrix has you...");
}
}
The simplest way is to send http request directly to the Telegram BOT API as url string, you may test those url strings even in your browser, please see details in my another answer here:
https://stackoverflow.com/a/57341990/11687179
at the first step you have to generate a bot in botfather then use the code in bellow in C#
private void SendMessage(string msg)
{
string url = "https://api.telegram.org/{botid}:{botkey}/sendMessage?chat_id={#ChanalName}&text={0}";
WebClient Client = new WebClient();
/// If you need to use proxy
if (Program.UseProxy)
{
/// proxy elements are variable in Program.cs
Client.Proxy = new WebProxy(Program.ProxyUrl, Program.ProxyPort);
Client.Proxy.Credentials = new NetworkCredential("hjolany", "klojorasic");
}
Client.DownloadString(string.Format(url, msg));
}));
}
Telegram has an official API that can do exactly what you need, you will have to look into http requests though..
Here is the documentation on sending a message:
Function
messages.sendMessage
Params
peer InputPeer User or chat where a message will be sent
message string Message text
random_id long Unique client message ID required to prevent message resending
Query example
(messages.sendMessage (inputPeerSelf) "Hello, me!" 12345678901)
Return errors
Code Type Description
400 BAD_REQUEST PEER_ID_INVALID Invalid peer
400 BAD_REQUEST MESSAGE_EMPTY Empty or invalid UTF8 message was sent
400 BAD_REQUEST MESSAGE_TOO_LONG Message was too long.
Current maximum length is 4096 UTF8 characters
For the full documentation go here.

How to force IIS to send response headers without sending response body and closing connection

I am trying to stream dynamically generated data to a client over HTTP using IIS, and the connection has to remain open for a long period of time, and the server will send periodic status updates to the client while it is performing a time-consuming operation.
This MUST all be handled within ONE request, but I am using a WebClient.OpenRead() stream, which cannot be opened until the headers are sent.
How can I force IIS to send headers to the client, and later send a response body?
This behaviour is normally achievable by setting KeepAlive to true and setting Expect header to "100 and continue". By doing this, server will send the headers with result code 100.
I am not sure if this is possible using WebClient.
Use HttpWebRequest instead to be able to set the values above. In fact WebClient does nothing magical but using GET to get the data. Here is the code for calling OpenRead in Reflector:
try
{
request = this.m_WebRequest = this.GetWebRequest(this.GetUri(address));
Stream responseStream = (this.m_WebResponse = this.GetWebResponse(request)).GetResponseStream();
if (Logging.On)
{
Logging.Exit(Logging.Web, this, "OpenRead", responseStream);
}
stream2 = responseStream;
}
catch (Exception exception)
{
//

Categories