Azure / azure-apihub-sdk

ApiHub Pro Dev SDK
MIT License
8 stars 7 forks source link

Connecting to SaaS table #1

Closed myaesubi closed 7 years ago

myaesubi commented 7 years ago

Hi, I'm using the NuGet package in Function Apps to integrate as input with SaaS table which is linked to a SQL Server instance in an Azure VM. there is no output, it's a timer function app.

Is there any requirement for SaaS connection to make the SQL server reachable, I set the inbound rules in security group to allow request from IPs associated with Func App. Following the sample code in here, I keep getting "Exception: Response status code does not indicate success: 400 (Bad Request)." error or,

"Exception while executing function: Functions.PushAggFuncApp. Microsoft.Azure.WebJobs.Script: One or more errors occurred. System.Net.Http: Response status code does not indicate success: 404 (Not Found)."

In addition, the "ContinuationToken" class usage create compile time error: the class does not exist though its namespace "Microsoft.Azure.ApiHub" is stated in the code.

Thanks for any insight, Mohammad

safihamid commented 7 years ago

Hi,

Please take a look at here for a sample of how to bind to a SaaS table. https://github.com/Azure/azure-webjobs-sdk-templates/tree/dev/Templates/SaaSTable-CSharp

You will need to create the connection using the functions portal.

myaesubi commented 7 years ago

Thanks I got that all right. My SQL Server instance is in the same VNET as the function App, however the SaasConnection being rejected with the following error upon executing the following lines in accordance to the sample provided earlier:

var segment = await aggregateSync.ListEntitiesAsync(continuationToken: continuationToken);

Exception:Response status code does not indicate success: 404 (Not Found).

Is there any criteria for Saas Connection?

Thanks, Mohammad reza

safihamid commented 7 years ago

Can you please include your function and json file? Does this work fine with Sql Azure but not with Sql Server on VNET?

myaesubi commented 7 years ago

I didn't test in SQL Azure, rather on SQL server on VNET. btw, the Function Apps though they are listed as 'App Services' and they are some kind of website, do not allow to select 'Networking' configuration.

Please find below the files requested.

Thanks in advance, Mohammad reza

function.json file:

{ "bindings": [ { "type": "manualTrigger", "direction": "in", "name": "input" }, { "type": "apiHubTable", "name": "aggregateSync", "dataSetName": "default", "connection": "sql1_SQL", "direction": "in", "tableName": "ctl.AggSync" } ], "disabled": false } run.csx file

`#r "Microsoft.Azure.ApiHub.Sdk"

using System; using System.Net; using Microsoft.Azure.ApiHub;

public class AggregateSync { public int SyncId { get; set; } public int CustomerId { get; set; } public DateTime SyncDateTime { get; set; } public int RunId {get;set;} public string Action {get;set;} public string Reason {get;set;} }

public static async void Run(string input, ITable aggregateSync,TraceWriter log) { ContinuationToken continuationToken = null; do { try { var segment = await aggregateSync.ListEntitiesAsync(continuationToken: continuationToken); log.Info("segment counts:"+segment.Items.Count()); foreach (var item in segment.Items) { log.Info(item.Action + " " + item.Reason); log.Info(item.SyncDateTime.ToString("u")); }

        continuationToken  = segment.ContinuationToken; ;
    }
    catch(Exception e)
    {
        log.Info("Exception:" + e.Message);
    }

}
while (continuationToken != null);

}`

safihamid commented 7 years ago

@emilcicos Do you know if we ever support Sql Server on VNET for ApiHubTable?

myaesubi commented 7 years ago

Any updates on this appreciated.

Thanks, Mohammad Reza