私はWCFサービスで "BluetoothLEAdvertisementWatcher" を使用したいC#の - Windows.winmdを使用してWCFサービスで
public override void StartWathchingAsync()
{
BluetoothLEAdvertisementWatcher BluetoothWatcher = new BluetoothLEAdvertisementWatcher();
}
しかし、私は "BluetoothLEAdvertisementWatcher" のインスタンスを作成するとき、私は
下のエラーが出ますmscorlib.dllで 'System.ServiceModel.FaultException`1'の未処理例外が発生しました
追加情報:パラメーターが正しくありません。 ( HRESULTからの例外:0x80070057が(E_INVALIDARG))
アンExceptionDetail、おそらくその値が真 IncludeExceptionDetailInFaults =、作成者: System.ArgumentExceptionの:パラメータが間違っています。 CでMeasuringDeviceService.DeviceService.GetDataで MeasuringDeviceService.MeasuringDeviceClasseis.XiaomiMiScale.StartWathchingAsync(で) (MeasuringDevice measuringDevice):(0x80070057が(E_INVALIDARG) HRESULTからの例外):\ユーザーは\ MahdKodak \プログラマー\デスクトップ\プロジェクト MahdKodakを\しますMeasuringDeviceService \ DeviceService.svc.cs:Cで MeasuringDeviceService.DeviceService.GetDataXiaomiMiScale(xiaomiMiScale xiaomiMiScale)でのライン 37:\ユーザーは MahdKodak \ MahdKodak \ MeasuringDeviceService \ DeviceService.svc.csプログラマー\デスクトップ\プロジェクト\:ライン 25 SyncInvokeGetDataXiaomiMiScale(Object、Object []、Object []) at System.ServiceModel.Dispatcher.SyncMethodInvoker。 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc & RPCでSystem.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc & RPC)で([] &出力オブジェクト、[]入力オブジェクト、オブジェクト インスタンス)を呼び出します) System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpcで System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc & RPC)で System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc & RPC)で System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11でSystem.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc & RPC)で System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc & RPC)(AT RPC) System.ServiceModel.Dispatcher.MessageRpcで System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc & RPC)でMessageRpc & RPC)。プロセス(ブール isOperationContextSet)
そして、私は以下のコード行をコメント、私のプログラムの作業も
//BluetoothLEAdvertisementWatcher BluetoothWatcher = new BluetoothLEAdvertisementWatcher();
EDIT:
これは私のコード
サービスですコード:
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;
}
}
}
他のクラス:どこかの例外がスローされるように引き起こしているMeasuringDeviceService.DeviceService.GetData(MeasuringDevice measuringDevice)で
[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();
}
}
例外の原因となるコード行がメソッドに1行しかない場合は、もちろんコメント行のときにメソッドがうまく動作します。 BluetoothLEAdvertisementWatcherコンストラクタにコンストラクタパラメータが必要かどうかチェックしましたか? APIにアクセスできますか、コード全体を投稿することができますか? – Ayusman