Is it possible to create both client and server using IIOP.Net - c#

I'm new to IIOP.Net.
I have done a Adder app using IIOP.Net ( Server is written in Java and client is C#). Now I want to create both client and server using IIOP.Net written in C# ( I know there are many easier ways to do that but I just want to use IIOP.Net).
What I did is:
Create Server. OK
Because my client is C#, I don't have the idl file to compile to the cls, so I did a bad trick here. I create a libary that is the implementation of my corba object, then build it to a .dll file, finally copy it to my client project ( add references...).
Create client. OK
Run Server. OK
Run Client. Not OK
I got an error:
An unhandled exception of type 'omg.org.CosNaming.NamingContext_package.NotFound' occurred in mscorlib.dll
at line:
Adder a = (Adder) nm.resolve(nameService);
//where Adder is implementation of corba object (in library).
I have no idea to fix that. I googled it but does not give me any expected result.
Hope to see your answers soon.
Thank you.

Related

gRPC client having lots of issues and not working

I started using gRPC with Visual Studio 2022 and never saw so many issues as now.
When I wanted to create an additional Proto file I got the error saying that I need to specify the language. That's weird, because I selected the proper option which is designed for C#. So it never worked and I simply had to copy default greeter file.
I created the console app which uses this default greeter service and it even worked. But I added the additional proto and created another fairy simple service and it did not want to compile it referring to some missing types of something. I can't remember the exact error message but I resolved it only by reducing the grpc.* package version to 2.27.I found this answer by googling and I find it weird that Microsoft releases something what does not work in the most simple case scenario.
I decided to test my new test grpc service and created the client:
var channel = GrpcChannel.ForAddress("https://localhost:5001");
var client = new Greeter.GreeterClient(channel);
var reply = await client.MySimpleMethodAsync(new MyRequest { Id = 123 });
Console.WriteLine(reply.Message);
Console.ReadKey();
The MySimpleMethodAsync method is very simple, it just reads the record from the DB using Dapper, nothing special.
Surprisingly there was no compilation error, but when I tried to run it (along with the server app) I got the exception on the line var reply = await client.MySimpleMethodAsync, saying Grpc.Core.RpcException: 'Status(StatusCode=Unimplemented, Detail="Service is unimplemented.")'
I don't understand why it says so. The service is implemented, it's compilable! Googling did not help but I found that other people are having the same issue too.
Eventually I found that if I modify the grpc service and for some reason it does not like it and then I rollback the changes, it's not compilable anymore! I clearn solution, rebuild it - nothing helps! The only thing which helps is addting the brand new project and copy pasting the previous "stable" code.
I've never seen such the ...technology that never works!
Anyway, now the most important issue for me is #3 , why it says the service is not implemented?

How to connect my Xamarin app with local mySQL server?

I'm trying connect to mySQL server with code below: (just part of my whole code)
using MySql.Data.MySqlClient;
//...
public void ConnectToServer()
{
string ConnectionString =
"Server=DESKTOP-91JG566;Database=db_server;Uid=user;Pwd=123456A+;";
MySqlConnection cConn = new MySqlConnection(ConnectionString);
cConn.Open(); // this returns the exception
serverStatus = cConn.Ping() ? serverStatus = "connected" : serverStatus = "disconnected";
}
I'm using MySQL Workbench, there is my server with database https://i.stack.imgur.com/jxn84.jpg
The exception says: System.TypeInitializationException: 'The type initializer for 'MySql.Data.MySqlClient.MySqlConfiguration' threw an exception.'
I have searched about it, and even though I enabled "SQL Server Debugging" in project properties, things are the same.
The problem might be caused because I have bad connection string, I am not sure.
My goal is to communicate with the server, query him, reveive orders etc...
As Jason already mentioned this is a horrible idea to do. Instead, I suggest you build some mini REST API or even use some of the serverless services out there.
When you have that REST API or Azure Function ready then you can communicate with them using your C# code, more precisely using HttpClient from the .NET.
Your mobile app will be the client which will "talk" to REST API, and REST API will proceed with your request and make the request to the DB, grab some data and return you JSON or XML which you can, later on, deserialize into C# objects and show to the user.
The most simple example is located on the MS Docs page here, so you can take a look.
Wishing you lots of luck with coding!

Writing Variables via QuickOPC in C# (Visual Studio)

my project is about writing an OPC UA Client, to read and write variables on a Siemens PLC OPC UA Server. I'm using Visual Studio 2017 Enterprise and installed the Quick OPC Toolkit from OPClabs to get started and try to connect. To program the client, I'm using Windows Forms and C#.
Connecting with the server and reading variables is working just fine, but writing them gives me a headache:
1.) Before I started programming on my own, I downloaded the OPC UA Sample Client from the OPC Foundation (if someone needs the download-link just ask, the download is hard to find). I connected to the server and could browse through the variables, but the write function was greyed out/not available.
2.) I started programming a very simple client, but also failed to write variables. Reading via Live Binding (http://opclabs.doc-that.com/files/onlinedocs/QuickOpc/2018.2/User%27s%20Guide%20and%20Reference-QuickOPC/webframe.html#Making%20a%20first%20OPC%20UA%20application%20using%20Live%20Binding.html) is working, also reading them by using easyUAClient.Read() works. I tried to write a variable with this code:
namespace ErsteOPCUAVerbindung{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var easyUAClient = new EasyUAClient();
easyUAClient.WriteValue("opc.tcp://OpcUaClient:password#192.168.216.1:4840/", "nsu=SinumerikVarProvider;ns=2;s=/NC/_N_NC_TEA_ACX/$MN_PLC_CYCLIC_TIMEOUT", 1);
}
}}
but I keep getting an exception:
OpcLabs.EasyOpc.UA.OperationModel.UAException: "An OPC-UA operation failure with error code -2144010240 (0x80350000) occurred, originating from 'OpcLabs.EasyOpcUA'. The inner OPC-UA service exception with service result 'BadAttributeIdInvalid' contains details about the problem."
{"OPC-UA service result - An error specific to OPC-UA service occurred.\r\n---- SERVICE RESULT ----\r\nStatusCode: {BadAttributeIdInvalid} = 0x80350000 (2150957056)\r\n"}
I have no idea what is causing this. I suspected, that maybe some kind of access restriction is the reason, but I can't find any hints about it in the documentations and besides I'm logged in as administrator anyway.
Has anyone an Idea? Thank you.
I have had one more look at your code, and the way you pass in the user name and password (in the URL itself) is definitely not correct. The way it is given now it is essentially ignored. It may or may not be the cause for the problem with the Write, but it definitely needs to be changed. The proper way of specifying the user name and password would be:
var client = new EasyUAClient();
var endpointDescriptor = new UAEndpointDescriptor("opc.tcp://192.168.216.1:4840/");
endpointDescriptor.UserIdentity = UserIdentity.CreateUserNameIdentity("OpcUaClient", "password");
client.WriteValue(endpointDescriptor, "nsu=SinumerikVarProvider;ns=2;s=/NC/_N_NC_TEA_ACX/$MN_PLC_CYCLIC_TIMEOUT", 1);
Update: I found a documentation, which explained, that the administrator does not have write rights by default and how you can change that. You need to call the methode GiveUserAccess and pass two Arguments, the Username and "SinuWriteAll" (the second one is kind of hidden). I'll try it now with C# and post my solution if it works.

Server.CreateObject + Server Context + COM :-)

I am implementing a COM component using .net for a few outdated components for a server migration task.
The old component was used to receive an image path on the current server, convert it to a jpeg and save the converted image in the same path.
This is trivial to do in .net, however my main problem is obtaining the server context. I am not sure how to do either one of the following:
saving the image to the same path that the original image was retrieved from
or sending the image directly to the response stream (avoiding the need to save the converted image)
The component is being called within a class ASP page (yes, unfortunately!) using:
Server.CreateObject("Component.Class")
Is there anyway in the implementing .net code that I can obtain a reference to the Server object that created the component? I was hoping that if I could obtain a reference to the server, I could then obtain the appropriate context to write back to the response stream.
I have worked this out, obtaining a few clues for the internet and google. Thought I should post this in case anyone else has the same problem.
Obtaining the server context was a matter of including the following references:
COMSVCLib (should already be in your COM section when adding references to your project)
ASPTypeLibrary: Look for: "Microsoft Active Server Pages Object Library". If you don't see this immediately in your COM section, then you will need to add this from "windows programs and features". Add the following feature: Internet Information Services -> WWW Services -> ASP
Working out the above was the hardest thing :-) After that, its very simple to reference your server and other intrinsic ASP objects:
COMSVCSLib.AppServer aspServer = new COMSVCSLib.AppServer();
COMSVCSLib.ObjectContext oc = aspServer.GetObjectContext();
ASPTypeLibrary.Server server = (ASPTypeLibrary.Server)oc["Server"];
You can do the same with with other ASP objects such as Request and Response.

JSchException verify: False C# .NET Scp SSH

I want to connect to remote server to upload some files via SCP/SSH.
I am using SharpSSH for this but it doesnt work.
Everytime the ScpClint wants to connect i get the JSchException verify: False.
Here is my code:
Scp scpClient = new Scp();
scpClient.To(#"C:localPath", "hostIP", "/var/...", sshUser, sshPwd);
Does anybody an have any suggestions on how to fix this problem? Maybe another library? I also tried Renci.SshNet but there I can connect or it doesn't give any errors, but no matter what I try to upload nothing is to find on the Server.
Which version of the library are you using? That code is fairly old and unmaintained. My usual recommendation is to try SSHNet since that's a much more solid library, written for .NET, but you said you've already tried that. Perhaps it's a problem on the remote side if you cannot connect with either of the libraries?

Categories