You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/machine-learning/v1/how-to-authenticate-web-service.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ ms.author: larryfr
8
8
ms.reviewer: sehan
9
9
ms.service: azure-machine-learning
10
10
ms.subservice: inferencing
11
-
ms.date: 11/16/2022
11
+
ms.date: 03/11/2025
12
12
ms.topic: how-to
13
13
ms.custom: UpdateFrequency5, sdkv1
14
14
---
@@ -31,7 +31,7 @@ The model deployments created by Azure Machine Learning can be configured to use
31
31
32
32
Web-services deployed on Azure Kubernetes Service (AKS) have key-based auth *enabled* by default.
33
33
34
-
Azure Container Instances (ACI) deployed services have key-based auth *disabled* by default, but you can enable it by setting `auth_enabled=True`when creating the ACI web-service. The following code is an example of creating an ACI deployment configuration with key-based auth enabled.
34
+
Azure Container Instances (ACI) deployed services have key-based auth *disabled* by default, but you can enable it by setting `auth_enabled=True`when creating the ACI web-service. The following code is an example of creating an ACI deployment configuration with key-based auth enabled.
35
35
36
36
```python
37
37
from azureml.core.webservice import AciWebservice
@@ -113,9 +113,9 @@ print(token)
113
113
>
114
114
> We strongly recommend that you create your Azure Machine Learning workspace in the same region as your Azure Kubernetes Service cluster.
115
115
>
116
-
> To authenticate with a token, the web service will make a call to the region in which your Azure Machine Learning workspace is created. If your workspace region is unavailable, you won't be able to fetch a token for your web service, even if your cluster is in a different region from your workspace. The result is that Microsoft Entra authentication is unavailable until your workspace region is available again.
116
+
> To authenticate with a token, the web service makes a call to the region in which your Azure Machine Learning workspace is created. If your workspace region is unavailable, you aren't able to fetch a token for your web service, even if your cluster is in a different region from your workspace. The result is that Microsoft Entra authentication is unavailable until your workspace region is available again.
117
117
>
118
-
> Also, the greater the distance between your cluster's region and your workspace region, the longer it will take to fetch a token.
118
+
> Also, the greater the distance between your cluster's region and your workspace region, the longer it takes to fetch a token.
> The IP address will be different for your deployment. Each AKS cluster will have its own IP address that is shared by deployments to that cluster.
107
+
> The IP address isdifferent for your deployment. Each AKS cluster has its own IP address that is shared by deployments to that cluster.
108
108
109
109
### Secured web service
110
110
@@ -214,7 +214,7 @@ For information on enabling CORS support in your service, see [Cross-origin reso
214
214
215
215
## Call the service (C#)
216
216
217
-
This example demonstrates how to use C# to call the web service created from the [Train within notebook](https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/notebook_runner/training_notebook.ipynb) example:
217
+
This example demonstrates how to use C# to call a web service:
218
218
219
219
```csharp
220
220
using System;
@@ -301,181 +301,9 @@ The results returned are similar to the following JSON document:
301
301
[217.67978776218715, 224.78937091757172]
302
302
```
303
303
304
-
## Call the service (Go)
305
-
306
-
This example demonstrates how to use Go to call the web service created from the [Train within notebook](https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/notebook_runner/training_notebook.ipynb) example:
307
-
308
-
```go
309
-
package main
310
-
311
-
import (
312
-
"bytes"
313
-
"encoding/json"
314
-
"fmt"
315
-
"io/ioutil"
316
-
"net/http"
317
-
)
318
-
319
-
// Features for this model are an array of decimal values
320
-
type Features []float64
321
-
322
-
// The web service input can accept multiple sets of values for scoring
323
-
type InputData struct {
324
-
Data []Features `json:"data",omitempty`
325
-
}
326
-
327
-
// Define some example data
328
-
var exampleData= []Features{
329
-
[]float64{
330
-
0.0199132141783263,
331
-
0.0506801187398187,
332
-
0.104808689473925,
333
-
0.0700725447072635,
334
-
-0.0359677812752396,
335
-
-0.0266789028311707,
336
-
-0.0249926566315915,
337
-
-0.00259226199818282,
338
-
0.00371173823343597,
339
-
0.0403433716478807,
340
-
},
341
-
[]float64{
342
-
-0.0127796318808497,
343
-
-0.044641636506989,
344
-
0.0606183944448076,
345
-
0.0528581912385822,
346
-
0.0479653430750293,
347
-
0.0293746718291555,
348
-
-0.0176293810234174,
349
-
0.0343088588777263,
350
-
0.0702112981933102,
351
-
0.00720651632920303,
352
-
},
353
-
}
354
-
355
-
// Set to the URIfor your service
356
-
var serviceUri string="<your web service URI>"
357
-
// Set to the authentication key or token (ifany) for your service
358
-
var authKey string="<your key or token>"
359
-
360
-
func main() {
361
-
// Create the input data from example data
362
-
jsonData := InputData{
363
-
Data: exampleData,
364
-
}
365
-
// Create JSONfrom it and create the body for the HTTP request
// These next two are only needed if using an authentication key
375
-
bearer := fmt.Sprintf("Bearer %v", authKey)
376
-
request.Header.Add("Authorization", bearer)
377
-
378
-
// Send the request to the web service
379
-
resp, err := client.Do(request)
380
-
if err != nil {
381
-
fmt.Println("Failure: ", err)
382
-
}
383
-
384
-
// Display the response received
385
-
respBody, _ := ioutil.ReadAll(resp.Body)
386
-
fmt.Println(string(respBody))
387
-
}
388
-
```
389
-
390
-
The results returned are similar to the following JSON document:
391
-
392
-
```json
393
-
[217.67978776218715, 224.78937091757172]
394
-
```
395
-
396
-
## Call the service (Java)
397
-
398
-
This example demonstrates how to use Java to call the web service created from the [Train within notebook](https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/notebook_runner/training_notebook.ipynb) example:
399
-
400
-
```java
401
-
import java.io.IOException;
402
-
import org.apache.http.client.fluent.*;
403
-
import org.apache.http.entity.ContentType;
404
-
import org.json.simple.JSONArray;
405
-
import org.json.simple.JSONObject;
406
-
407
-
public class App {
408
-
// Handle making the request
409
-
public static void sendRequest(String data) {
410
-
// Replace with the scoring_uri of your service
411
-
String uri = "<your web service URI>";
412
-
// If using authentication, replace with the auth key or token
413
-
String key = "<your key or token>";
414
-
try {
415
-
// Create the request
416
-
Content content = Request.Post(uri)
417
-
.addHeader("Content-Type", "application/json")
418
-
// Only needed if using authentication
419
-
.addHeader("Authorization", "Bearer "+ key)
420
-
// Set the JSON data as the body
421
-
.bodyString(data, ContentType.APPLICATION_JSON)
422
-
// Make the request and display the response.
423
-
.execute().returnContent();
424
-
System.out.println(content);
425
-
}
426
-
catch (IOException e) {
427
-
System.out.println(e);
428
-
}
429
-
}
430
-
public static void main(String[] args) {
431
-
// Create the data to send to the service
432
-
JSONObject obj = new JSONObject();
433
-
// In this case, it's an array of arrays
434
-
JSONArray dataItems = new JSONArray();
435
-
// Inner array has 10 elements
436
-
JSONArray item1 = new JSONArray();
437
-
item1.add(0.0199132141783263);
438
-
item1.add(0.0506801187398187);
439
-
item1.add(0.104808689473925);
440
-
item1.add(0.0700725447072635);
441
-
item1.add(-0.0359677812752396);
442
-
item1.add(-0.0266789028311707);
443
-
item1.add(-0.0249926566315915);
444
-
item1.add(-0.00259226199818282);
445
-
item1.add(0.00371173823343597);
446
-
item1.add(0.0403433716478807);
447
-
// Add the first set of data to be scored
448
-
dataItems.add(item1);
449
-
// Create and add the second set
450
-
JSONArray item2 = new JSONArray();
451
-
item2.add(-0.0127796318808497);
452
-
item2.add(-0.044641636506989);
453
-
item2.add(0.0606183944448076);
454
-
item2.add(0.0528581912385822);
455
-
item2.add(0.0479653430750293);
456
-
item2.add(0.0293746718291555);
457
-
item2.add(-0.0176293810234174);
458
-
item2.add(0.0343088588777263);
459
-
item2.add(0.0702112981933102);
460
-
item2.add(0.00720651632920303);
461
-
dataItems.add(item2);
462
-
obj.put("data", dataItems);
463
-
464
-
// Make the request using the JSON document string
465
-
sendRequest(obj.toJSONString());
466
-
}
467
-
}
468
-
```
469
-
470
-
The results returned are similar to the following JSON document:
471
-
472
-
```json
473
-
[217.67978776218715, 224.78937091757172]
474
-
```
475
-
476
304
## Call the service (Python)
477
305
478
-
This example demonstrates how to use Python to call the web service created from the [Train within notebook](https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/notebook_runner/training_notebook.ipynb) example:
306
+
This example demonstrates how to use Python to call a web service:
479
307
480
308
```python
481
309
import requests
@@ -680,14 +508,6 @@ For a utility that can create client libraries from the specification, see [swag
680
508
> [!TIP]
681
509
> You can retrieve the schema JSON document after you deploy the service. Use the [swagger_uri property](/python/api/azureml-core/azureml.core.webservice.local.localwebservice#swagger-uri) from the deployed web service (for example, `service.swagger_uri`) to get the URI to the local web service's Swagger file.
682
510
683
-
## Consume the service from Power BI
684
-
685
-
Power BI supports consumption of Azure Machine Learning web services to enrich the data in Power BIwith predictions.
686
-
687
-
To generate a web service that's supported for consumption in Power BI, the schema must support the format that's required by Power BI. [Learn how to create a Power BI-supported schema](./how-to-deploy-advanced-entry-script.md#power-bi-compatible-endpoint).
688
-
689
-
Once the web service is deployed, it's consumable from Power BI dataflows. [Learn how to consume an Azure Machine Learning web service from Power BI](/power-bi/service-machine-learning-integration).
690
-
691
511
## Next steps
692
512
693
513
To view a reference architecture for real-time scoring of Python and deep learning models, go to the [Azure architecture center](/azure/architecture/reference-architectures/ai/realtime-scoring-python).
0 commit comments