Java C#-在WCF服务中使用Windows.winmd
我想在WCF服务中使用“BluetoothLEAdvertisementWatcher”Java C#-在WCF服务中使用Windows.winmd,java,c#,.net,wcf,Java,C#,.net,Wcf,我想在WCF服务中使用“BluetoothLEAdvertisementWatcher” public override void StartWathchingAsync() { BluetoothLEAdvertisementWatcher BluetoothWatcher = new BluetoothLEAdvertisementWatcher(); } 但当我创建“BluetoothLEAdvertisementWatcher”的
public override void StartWathchingAsync()
{
BluetoothLEAdvertisementWatcher BluetoothWatcher = new BluetoothLEAdvertisementWatcher();
}
但当我创建“BluetoothLEAdvertisementWatcher”的实例时,我得到了下面的错误
mscorlib.dll中发生“System.ServiceModel.FaultException”“1”类型的未处理异常
附加信息:参数不正确。(不适用于
HRESULT:0x80070057(E_INVALIDARG))
ExceptionDetail,可能是由
IncludeExceptionDetailInFaults=true,其值为:
System.ArgumentException:参数不正确。(不适用于
HRESULT:0x80070057(E_INVALIDARG))在
测量设备服务.测量设备类.XiaomiMiScale.StartWathChinaGasync()
在MeasureingDeviceService.DeviceService.GetData(测量设备
C:\Users\Programmer\Desktop\Project中的测量设备)
MahdKodak\MahdKodak\MeasuringDeviceService\DeviceService.svc.cs:line
37在
测量DeviceService.DeviceService.GetDataXiaomiScale(XiaomiScale
在C:\Users\Programmer\Desktop\Project中使用
MahdKodak\MahdKodak\MeasuringDeviceService\DeviceService.svc.cs:line
25在SyncInvokeGetDataScale上(对象,对象[],对象[])
位于System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(对象
实例、对象[]输入、对象[]和输出)
System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&
rpc)在
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&
rpc)在
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc&
rpc)在
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&
rpc)在
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&
rpc)在
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&
rpc)在
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&
rpc)在
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc&
rpc)在
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&
rpc)位于System.ServiceModel.Dispatcher.MessageRpc.Process(布尔值
等操作上下文集)
当我注释下面的代码行时,我的程序运行良好
//BluetoothLEAdvertisementWatcher BluetoothWatcher = new BluetoothLEAdvertisementWatcher();
编辑:
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;
}
}
}
[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();
}
}
这是我的密码
服务代码:
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;
}
}
}
[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();
}
}
其他类别:
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;
}
}
}
[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();
}
}
问题可能出现在MeasuringDeviceService.MeasuringDeviceClass.XiaomiMiScale.StartWathchingAsync()中,也可能出现在MeasuringDeviceService.DeviceService.GetData(MeasuringDeviceMeasuringDevice)中导致引发异常的某个位置 在堆栈中看到WCF的原因是,上面的代码正在WCF服务中执行,并且当发生错误时,异常将通过FaultException发送回客户端 我不知道您的代码或系统,但我的第一个猜测是您需要了解DeviceService.GetData()的功能以及如何使其以独立的方式工作 编辑:尝试运行BluetoothLEAdvertisementWatcher BluetoothWatcher=new BluetoothLEAdvertisementWatcher();在WCF领域之外的独立方法中调用
当您这样做时,它是否按预期工作?您是否可以在服务器端设置一个断点,准确地查看抛出的异常并粘贴调用堆栈?如果您的方法只有一行导致异常的代码,那么在注释该行时,您的方法当然可以正常工作。您是否已检查BluetoothLEAdvertisementWatcher构造函数是否需要构造函数参数?你有访问API的权限吗,或者可能会发布整个代码?谢谢你,我在控制台应用程序中进行了测试,效果很好,我为我的问题制作了一个Gif,我没有访问源代码的权限,但是你可能想尝试这样的东西:new BluetoothLEAdvertisementWatcher{ScanningMode=BluetoothLEScanningMode.Active};watcher.Start();没有解决我发现这个关于元数据的问题是否相关?它不相关。问题在于BluetoothLEAdvertisementWatcher以及它如何在无参数公共构造函数中引发异常。你所展示的看起来像是一个bug,你应该考虑报告它。确保你提供了一份完整的工作报告。