I have a problem with connecting to our LDAP server, using the NuGet package “Novell.Directory.Ldap.NETStandard2_0”.
My application is a Xamarin.Forms, with the Andoid & UWP part, based on NetStandard 2.0, using Visual Studio 2019, updated.
I could not find any built-in functionality in Netcore2.0 for using LDAP,
That is why I used the Nuget Package (Novell.Directory.Ldap.NETStandard2_0 by Novell, dsbenghe, mkostreba).
I have also used an LDAP query tool for Windows to test the connection, and that works.
But when I try to establish a connection in my app, I get an error with error code 91.
I have tried it with the full hostname, and with the direct ip address of the domain server, but I get the same error result. I have tried this with debugging UWP, not android.
I haven't started on making a correct credentials query yet, because the connection itself should first be ok.
This is my code: (under a simple button clicked)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Novell.Directory.Ldap;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using System.ComponentModel;
namespace App1.view
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Page2 : ContentPage
{
public Page2()
{
InitializeComponent();
}
private void button2_Clicked(object sender, EventArgs e)
{
try
{
LdapConnection conn = new LdapConnection();
conn.Connect("ldapserverhostname", 389);
conn.Bind("username query", "some password");
DisplayAlert("Error", "succesvol", "ok");
conn.Disconnect();
}
catch (LdapException f)
{
DisplayAlert("Error", f.ResultCode.ToString(), "ok");
return;
}
catch (Exception f)
{
DisplayAlert("Error", f.Message, "ok");
return;
}
}
}
}
Who could help me with this?
update 16 apr 2020:
I have established a connection + successful bind with our LDAP server using WPF NetCore console application, and also with a WPF NetCore desktop application, using the same serverinfo and user query info.
But I cannot get this working under Xamarin.Forms UWP or with a dedicated UWP app. Firewall of the computer is out of the question (I believe), because I am able to communicate with the LDAP server in multiple ways.
I have tried it with sideloading my Xamarin.Forms UWP app, but no result. >> Jumps to the first catch, every time.
Besides using the Novell Ldap Nuget, I have also tried the Windows Compatibility Pack for NetCore app in my UWP and Xamarin.Forms UWP app, but that will result in an "not supported platform" error.
here is my working code from the WPF NetCore desktop app:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Novell.Directory.Ldap;
using Novell.Directory;
namespace WpfApp3
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
string ldapHost = "fullyhostname.com";
String loginDN = "CN=MyUserName,OU=HK,something=Users,DC=ourdomainname,DC=com";
String password = "mypassword";
LdapConnection conn = new LdapConnection();
try
{
conn.Connect(ldapHost, 389);
if (conn.Connected)
{
MessageBoxResult r = MessageBox.Show("connection succeeded");
}
conn.Bind(loginDN, password);
MessageBoxResult t = MessageBox.Show("bind succeeded");
}
catch (LdapException f)
{
Console.WriteLine("Error1:" + "code= " + f.ResultCode.ToString());
Console.WriteLine("Error1:" + "code= " + f.LdapErrorMessage);
return;
}
catch (Exception f)
{
Console.WriteLine("Error:" + f.Message);
return;
}
conn.Disconnect();
}
}
}
Related
I am attempting to use Microsoft's Bing Spellcheck API with a WPF application. I have a textbox where I enter in some text, and then a button that checks the spelling in the textbox, and should return the red line underneath anything that is misspelled. I think I have it programmed correctly, but nothing is happening when I click on the button. I am following along with Microsoft's code snippet on how to do this: https://dev.cognitive.microsoft.com/docs/services/56e73033cf5ff80c2008c679/operations/57855119bca1df1c647bc358
I understand that WPF does have a Spellcheck feature available, however I want to practice using some of Microsoft's Cognitive APIs for my own benefit.
Here is my code for my MainWindow.xaml.cs of the WPF application:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Net.Http.Headers;
using System.Net.Http;
using System.Web;
namespace Project1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
static async void MakeRequest()
{
MainWindow window = new MainWindow();
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
//Request headers
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "e94333d69eb6493d86aaa4b25e42d0d0");
//Request parameters
queryString["text"] = window.TextBox.Text;
var uri = "https://api.cognitive.microsoft.com/bing/v5.0/spellcheck/?" + queryString;
await client.GetAsync(uri);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
MakeRequest();
}
}
}
If anyone is able to help me understand what I am doing wrong, that would be great. I am completely new to using APIs so I am still trying to figure out exactly how to use them. Thanks!
As you mentioned that u don't know how to get the result I will show u an example.
You have to parse the reponse and update your TextBox by yourself.
static async void DownloadPage()
{
var queryString = HttpUtility.ParseQueryString(string.Empty);
queryString["text"] = "Bill Gatas";
queryString["mode"] = "spell";
var uri = "https://api.cognitive.microsoft.com/bing/v5.0/spellcheck/?" + queryString;
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "e94333d69eb6493d86aaa4b25e42d0d0");
using (var response = await client.GetAsync(uri))
{
string result = await response .Content.ReadAsStringAsync(); //Put here a breakpoint
}
}
}
If you put a breakpoint on result you will see that it contains the response (with suggestions) in JSON format.
My pc is connected to the router of the network i want to scan but the not wireless the pc is connected with a cable to the router.
But my android device is connected to the network wireless.
So in logic in this case the results in the list should be my pc and my android device.
This is what i'm using now managed wifi api:
managed wifi api
This is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NativeWifi;
namespace ScanWifi
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
WlanClient client = new WlanClient();
try
{
foreach (WlanClient.WlanInterface wlanIface in client.Interfaces)
{
Wlan.WlanBssEntry[] wlanBssEntries = wlanIface.GetNetworkBssList();
foreach (Wlan.WlanBssEntry network in wlanBssEntries)
{
int rss = network.rssi;
byte[] macAddr = network.dot11Bssid;
string tMac = "";
for (int i = 0; i < macAddr.Length; i++)
{
tMac += macAddr[i].ToString("x2").PadLeft(2, '0').ToUpper();
}
listView1.Items.Add("Found network with SSID {0}." + System.Text.ASCIIEncoding.ASCII.GetString(network.dot11Ssid.SSID).ToString());
listView1.Items.Add("Signal: {0}%."+ network.linkQuality);
listView1.Items.Add("BSS Type: {0}."+ network.dot11BssType);
listView1.Items.Add("MAC: {0}.", tMac);
listView1.Items.Add("RSSID:{0}", rss.ToString());
}
Console.ReadLine();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
When running the program i'm exception on WlanApi.cs on the line:
Wlan.ThrowIfError(
Wlan.WlanOpenHandle(Wlan.WLAN_CLIENT_VERSION_XP_SP2, IntPtr.Zero, out negotiatedVersion, out clientHandle));
System.ComponentModel.Win32Exception' occurred in ManagedWifi.dll
The service has not been started
For Windows 10, the service "WLAN AutoConfig" must be started for WlanClient to work. This service should be started automatically on a computer which has a WiFi adapter present. On a computer such as a desktop which does not have a WiFi adapter, the service startup type is probably Manual and not started; you can start it anyway and WlanClient should no longer throw any exceptions, but without a WiFi adapter, it won't see any interfaces, so you won't be able to get a list of networks.
According to the documentation of the [WlanOpenHandle ][1] function, the problem is that the Wireless Zero Configuration (WZC) service is not started on your machine:
WlanOpenHandle will return an error message if the Wireless Zero Configuration (WZC) service has not been started or if the WZC service is not responsive.
However, depending on your platform, it might also might be the case that you are simply passing the wrong parameters to the WlanOpenHandle function. Have you tried passing Wlan.WLAN_CLIENT_VERSION_LONGHORN as the first parameter?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WebcamControl;
using System.Drawing.Imaging;
using Microsoft.Expression.Encoder;
using System.Reflection;
namespace SMS
{
/// <summary>
/// Interaction logic for camphoto.xaml
/// </summary>
public partial class camphoto : Window
{
public camphoto()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
try
{
Binding bndg_1 = new Binding("SelectedValue");
bndg_1.Source = comboBox1;
webcam1.SetBinding(WebcamControl.Webcam.VideoDeviceProperty, bndg_1);
//set properties
webcam1.PictureFormat = ImageFormat.Jpeg;
webcam1.FrameRate = 30;
webcam1.FrameSize = new System.Drawing.Size(320, 240);
comboBox1.SelectedIndex = 0;
string str = Microsoft.Expression.Encoder.Devices.EncoderDeviceType.Video.ToString();
FindDevice();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void FindDevice()
{
var vidDevice = Microsoft.Expression.Encoder.Devices.EncoderDevices.FindDevices(Microsoft.Expression.Encoder.Devices.EncoderDeviceType.Video);
foreach (var data in vidDevice)
{
comboBox1.Items.Add(data.Name);
}
}
}
}
Hi Friends, This is my code what it is preview to webcam. But one error is coming when I'm debugging this.
"File Not found Exception was cought : Could not load file or assembly
'Microsoft.Expression.Encoder, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The
system cannot find the file specified."
I'm already added Microsoft.Expression.Encoder reference to project references. But I don't understand why it is coming. please help me.
Go to Project Properties -> Build section and change Platform target to x86
Did you check if your project profile is NOT ".Net Framework 4.0 Client Profile". If so please change to ".Net Framework 4.0".
Also ensure that the references section has the dll reference. Try to clean the solution and then rebuild and also cross verify the dll in the bin directory once.
I want to run the Skeinforge slicer program written in Python inside my Windows Phone 8 C# application. I have determined that I should probably use IronPython to do this, I have already determined that I can run Skeinforge inside the ipy.exe terminal I got when I installed IronPython. My problem though is that I am struggling to figure out how to host and run a Python script with IronPython inside Windows Phone 8. I have also already managed to get a simple hello world script running inside a Desktop Windows Forms application that transfers the applications console output to the Debug console with the following code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DebugWriter debugW = new DebugWriter();
Console.SetOut(debugW);
}
private void button1_Click(object sender, EventArgs e)
{
TextWriter tw = new StreamWriter("Test.py");
tw.Write(scriptBox.Text);
tw.Close();
try
{
var ipy = Python.CreateRuntime();
dynamic test = ipy.UseFile("Test.py");
}
catch (Exception ex)
{
Debug.WriteLine("Error: " + ex.Message);
}
}
}
}
And this is the DebugWriter:
class DebugWriter : TextWriter
{
private StringBuilder content = new StringBuilder();
public DebugWriter()
{
Debug.WriteLine("Writing console to debug");
}
public override void Write(char value)
{
base.Write(value);
if (value == '\n')
{
Debug.WriteLine(content.ToString());
content = new StringBuilder();
}
else
{
content.Append(value);
}
}
public override Encoding Encoding
{
get { return System.Text.Encoding.UTF8; }
}
}
I have no idea how to even add the IronPython libraries to my Windows Phone 8 application though as the standard libraries won't import. I have though tried compiling the apparently now defunct Windows Phone 7 libraries with the master source code and I can import these libraries, but I get absolutely no response on the debug terminal when I try to run my hello world script.
Do any of you have any idea how to get this woring in Windows Phone 8, if you know how to do this in Windows 8/Metro/RT then that would also probably work for WP8.
UPDATE:
I have looked at the debug output again and I seem to get this error when trying to use the WP7 libraries to run a hello world script:
A first chance exception of type 'System.NotImplementedException' occurred in Microsoft.Scripting.DLL
Error: The method or operation is not implemented.
I managed to get Skeinforge running on a modified version of IPY. You can get the source for my application here: http://skeinforgewp8.codeplex.com/
I'm working on cross domain implementation of SignalR in asp .net web application using VS 2010 .
My problems it that I'am unable to access HubConnection() from my application . I have installed SignalR version 0.5.3 . I have searched for namespace of HubConnection() but couldn't find any. Can anyone tell me the namespace of HubConnection() or the reason why I'm not able to access.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SignalR;
namespace SignalRVersion5
{
public partial class TestServerEvent : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
var connection = new HubConnection("http://localhost:58416/");
var chat = connection.CreateProxy("chat");
chat.On<string>("addMessage", Console.WriteLine);
try
{
connection.Start().Wait();
string msg = null;
while ((msg = Console.ReadLine()) != null)
{
chat.Invoke("send", msg).Wait();
}
}
catch (Exception ex)
{
using (var error = ex.GetError()) // NEW ERROR HANDLING FEATURES
{
Console.WriteLine(error.StatusCode);
}
}
}
}
}
You need to use the SignalR Client package available on NuGet: http://nuget.org/packages/Microsoft.AspNet.SignalR.Client
You should be using the 1.0.0 RC2 version of SignalR. 0.5.3 is out of date.
Once you install the correct client package, you should us the Microsoft.AspNet.SignalR.Client.Hubs namespace.
The documentation at https://github.com/SignalR/SignalR/wiki is continuously kept up to date with the latest versions of SignalR. The following documentation pertains to using the .NET client library with hubs: https://github.com/SignalR/SignalR/wiki/SignalR-Client-Hubs
Here is an example, using SignalR.Client 0.5.1.1. If you are creating a new project I would definitely recommend having a look at SignalR 1.0 first.
using SignalR.Client.Hubs;
var hubConnection = new HubConnection(HUB_URL);
var hub = hubConnection.CreateProxy(HUB_NAME);
Console.WriteLine("Starting connection");
await hubConnection.Start();
Console.WriteLine("Connected");
var start = DateTime.Now;
var question = new Question
{
Text = "text message",
Time = start.ToString("d")
}
};
await hub.Invoke("Ask", question);
hubConnection.Stop();