diff --git a/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/TwinClient.java b/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/TwinClient.java index 222e7d1875..214a29efa4 100644 --- a/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/TwinClient.java +++ b/service/iot-service-client/src/main/java/com/microsoft/azure/sdk/iot/service/twin/TwinClient.java @@ -321,11 +321,11 @@ public Twin replace(Twin twin, String ifMatch) throws IotHubException, IOExcepti URL url; if (twin.getModuleId() == null || twin.getModuleId().length() == 0) { - url = this.iotHubConnectionString.getUrlTwin(twin.getDeviceId()); + url = IotHubConnectionString.getUrlTwin(this.hostName, twin.getDeviceId()); } else { - url = this.iotHubConnectionString.getUrlModuleTwin(twin.getDeviceId(), twin.getModuleId()); + url = IotHubConnectionString.getUrlModuleTwin(this.hostName, twin.getDeviceId(), twin.getModuleId()); } TwinState twinState = new TwinState(twin.getTags(), twin.getDesiredProperties(), null); diff --git a/service/iot-service-samples/device-twin-sample/src/main/java/samples/com/microsoft/azure/sdk/iot/DeviceTwinSample.java b/service/iot-service-samples/device-twin-sample/src/main/java/samples/com/microsoft/azure/sdk/iot/DeviceTwinSample.java index 07b78a4a65..058914957a 100644 --- a/service/iot-service-samples/device-twin-sample/src/main/java/samples/com/microsoft/azure/sdk/iot/DeviceTwinSample.java +++ b/service/iot-service-samples/device-twin-sample/src/main/java/samples/com/microsoft/azure/sdk/iot/DeviceTwinSample.java @@ -105,8 +105,6 @@ private static void replaceDesiredProperties(TwinClient twinClient, Twin deviceT { deviceTwin.getDesiredProperties().put("temp", new Random().nextInt(TEMPERATURE_RANGE)); - // By replacing the twin rather than patching it, any desired properties that existed on the twin prior to this call - // that aren't present on the new set of desired properties will be deleted. System.out.println("Replacing Device twin"); deviceTwin = twinClient.replace(deviceTwin);