I want to use "BluetoothLEAdvertisementWatcher" in WCF Service
public override void StartWathchingAsync()
{
BluetoothLEAdvertisementWatcher BluetoothWatcher = new BluetoothLEAdvertisementWatcher();
}
But when I create instances of "BluetoothLEAdvertisementWatcher" I get the error below
An unhandled exception of type 'System.ServiceModel.FaultException`1' occurred in mscorlib.dll
Additional information: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is: System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)) at MeasuringDeviceService.MeasuringDeviceClasseis.XiaomiMiScale.StartWathchingAsync() at MeasuringDeviceService.DeviceService.GetData(MeasuringDevice measuringDevice) in C:\Users\Programmer\Desktop\Project MahdKodak\MahdKodak\MeasuringDeviceService\DeviceService.svc.cs:line 37 at MeasuringDeviceService.DeviceService.GetDataXiaomiMiScale(XiaomiMiScale xiaomiMiScale) in C:\Users\Programmer\Desktop\Project MahdKodak\MahdKodak\MeasuringDeviceService\DeviceService.svc.cs:line 25 at SyncInvokeGetDataXiaomiMiScale(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
And when I comment the code line below, my program work well
//BluetoothLEAdvertisementWatcher BluetoothWatcher = new BluetoothLEAdvertisementWatcher();
EDIT :
This is my code
Service Code :
public class DeviceService : IDeviceService
{
Semaphore DeviceSemaphor = null;
public DeviceService()
{
DeviceSemaphor = new Semaphore(1, 1);
}
public XiaomiMiScaleData GetDataXiaomiMiScale(XiaomiMiScale xiaomiMiScale)
{
return GetData(xiaomiMiScale) as XiaomiMiScaleData;
}
public MeasuringDeviceData GetData(MeasuringDevice measuringDevice)
{
try
{
measuringDevice.StartWathchingAsync();
return measuringDevice.LastData;
}
catch (Exception ex)
{
return null;
}
}
}
Other Classes :
[DataContract]
public class MeasuringDevice
{
[DataMember]
public MeasuringDeviceData LastData { get; set; }
public MeasuringDevice()
{
}
[DataMember]
public ulong DeviceBluetoothAddress { get; set; }
public virtual void StartWathchingAsync()
{
}
}
[DataContract]
public class XiaomiMiScale : MeasuringDevice
{
public XiaomiMiScale()
{
LastData = new XiaomiMiScaleData();
}
public override void StartWathchingAsync()
{
BluetoothLEAdvertisementWatcher BluetoothWatcher = new BluetoothLEAdvertisementWatcher();
}
}