How to add a SOAP parameter to a C# service reference - c#

I have created service references in Visual Studio 2017 from WSDL's provided by our client. One of them requires an attribute/parameter like:
<Item ActionCode="02">
I'm new to SOAP services and can't figure out how to add the ActionCode. I see it in the object browser and in the References.cs.
Here is my code so far (which works for a similar call with no attribute):
BYDUpdateTimeSvc.EmployeeTimeCreateRequestMessage_sync req = new BYDUpdateTimeSvc.EmployeeTimeCreateRequestMessage_sync()
{
BasicMessageHeader = new BYDUpdateTimeSvc.BusinessDocumentBasicMessageHeader(),
EmployeeTime = new BYDUpdateTimeSvc.EmployeeTimeCreateRequest()
{
EmployeeTimeAgreementItemUUID = new BYDUpdateTimeSvc.UUID { Value = rec.employeeTimeAgreement },
Item = new BYDUpdateTimeSvc.EmployeeTimeCreateRequestItem[1]
{
new BYDUpdateTimeSvc.EmployeeTimeCreateRequestItem()
{
TypeCode = activityCode,
PaymentTypeCode = locationCode,
EmployeeTimeValidity = _dateValidity
}
}
}
};
How do I add that parameter/attribute?

I don't know anything about the API you are using.
That said, have you tried setting the property using object initializer syntax.
BYDUpdateTimeSvc.EmployeeTimeCreateRequestMessage_sync req = new BYDUpdateTimeSvc.EmployeeTimeCreateRequestMessage_sync()
{
BasicMessageHeader = new BYDUpdateTimeSvc.BusinessDocumentBasicMessageHeader(),
EmployeeTime = new BYDUpdateTimeSvc.EmployeeTimeCreateRequest()
{
EmployeeTimeAgreementItemUUID = new BYDUpdateTimeSvc.UUID { Value = rec.employeeTimeAgreement },
Item = new BYDUpdateTimeSvc.EmployeeTimeCreateRequestItem[1]
{
new BYDUpdateTimeSvc.EmployeeTimeCreateRequestItem()
{
TypeCode = activityCode,
PaymentTypeCode = locationCode,
EmployeeTimeValidity = _dateValidity
}, // added comma
ActionCode = "02"; // set action code here
}
}
};

Related

How to get HangoutLink from Event created in Google Calendar API in C#?

I'm trying to create an event like this way:
calendarEvent.ConferenceData = new ConferenceData
{
ConferenceSolution = new ConferenceSolution
{
Key = new ConferenceSolutionKey
{
Type = "hangoutsMeet"
}
},
CreateRequest = new CreateConferenceRequest
{
RequestId = "qwsdimop",
ConferenceSolutionKey = new ConferenceSolutionKey
{
Type = "hangoutsMeet"
}
}
,
EntryPoints = new List<EntryPoint>
{
new EntryPoint
{
EntryPointType = "video",
}
}
};
I set the ConferenceDataVersion to this way:
EventsResource.InsertRequest request = service.Events.Insert(calendarEvent, "example#gmail.com");
request.ConferenceDataVersion = 1;
But I get and Error: Invalid conference type value
when I run the code without this line:
ConferenceSolutionKey = new ConferenceSolutionKey
{
Type = "hangoutsMeet"
}
the event is created correctly but doesn't get the hangoutlink
Does anyone know why that happens or how to do it the right way?

Is Universal Analytics C# SDK compatible with GA4?

I am using Google.Apis.AnalyticsReporting.v4 library for old google analytics views. How do I convert this code to GA4? I can't find a line about switching View Id to something else in code.
I have checked this post "How do I get view id in GA4", but my properties already exist and I don't see option to modify them after creation.
using (var svc = new AnalyticsReportingService(authInitializer.CreateInitializer()))
{
var dateRange = new DateRange
{
StartDate = analyticsParams.From.ToString("yyyy-MM-dd"),
EndDate = analyticsParams.To.ToString("yyyy-MM-dd")
};
var sessions = new Metric
{
Expression = "ga:sessions",
Alias = "Sessions"
};
var date = new Dimension { Name = "ga:date" };
var reportRequest = new ReportRequest
{
DateRanges = new List<DateRange> { dateRange },
Dimensions = new List<Dimension> { date },
Metrics = new List<Metric> { sessions },
ViewId = analyticsParams.ViewId, // <------------------------- My view id
};
var getReportsRequest = new GetReportsRequest
{
ReportRequests = new List<ReportRequest> { reportRequest }
};
var batchRequest = svc.Reports.BatchGet(getReportsRequest);
var response = batchRequest.Execute();
var reports = response.Reports.First();
return reports.Data.Rows.Select(x => new DataEntry()
{
Date = DateTime.ParseExact(x.Dimensions[0], "yyyyMMdd", CultureInfo.InvariantCulture),
Value = int.Parse(x.Metrics[0].Values[0]),
}).ToList();
}
You need to use the Google Analytics Data API V1 (currently in alpha) in order to access your GA4 properties. Here is a quick start sample for .NET which seems similar to what you are trying to do.
using Google.Analytics.Data.V1Alpha;
using System;
namespace AnalyticsSamples
{
class QuickStart
{
static void SampleRunReport(string propertyId)
{
// Using a default constructor instructs the client to use the credentials
// specified in GOOGLE_APPLICATION_CREDENTIALS environment variable.
AlphaAnalyticsDataClient client = AlphaAnalyticsDataClient.Create();
// Initialize request argument(s)
RunReportRequest request = new RunReportRequest
{
Entity = new Entity{ PropertyId = propertyId },
Dimensions = { new Dimension{ Name="city"}, },
Metrics = { new Metric{ Name="activeUsers"}, },
DateRanges = { new DateRange{ StartDate="2020-03-31", EndDate="today"}, },
};
// Make the request
RunReportResponse response = client.RunReport(request);
Console.WriteLine("Report result:");
foreach( Row row in response.Rows )
{
Console.WriteLine("{0}, {1}", row.DimensionValues[0].Value, row.MetricValues[0].Value);
}
}
static int Main(string[] args)
{
if (args.Length == 0 || args.Length > 2)
{
Console.WriteLine("Arguments: <GA4 property ID>");
Console.WriteLine("A GA4 property id parameter is required to make a query to the Google Analytics Data API.");
return 1;
}
string propertyId = args[0];
SampleRunReport(propertyId);
return 0;
}
}
}
Currently there aren't API available for GA4 Property. Furthermore GA4 does not provide Views, you have to use BigQuery to get data programmatically.

Need to add Parameters to NewActionConfiguration but cant use a foreach inside the definition

Using Axis Communications VAPIX WSDL APIs - I'm setting up a NewActionConfiguration which takes a number of parameters that I have saved in a List but the way the API documents have the implementation I cant loop through my parameter list XML objects while defining the newAction object.
//This is how the API docs say to do it:
NewActionConfiguration newAction = new NewActionConfiguration
{
TemplateToken = overlayToken,
Name = "Overlay Text",
Parameters = new ActionParameters
{
Parameter = new[]
{
new ActionParameter { Name = "text", Value = "Trigger:Active" },
new ActionParameter { Name = "channels", Value = "1" },
new ActionParameter { Name = "duration", Value = "15" }
}
}
};
//This is what I need to do:
NewActionConfiguration newAction = new NewActionConfiguration
{
Name = xmlPrimaryAction["Name"].InnerText,
TemplateToken = xmlPrimaryAction["ActionTemplate"].InnerText,
Parameters = new[]
{
foreach (ActionParameter actionParameter in actionParameterList)
{
new ActionParameter { Name = actionParameter.Name, Value = actionParameter.Value };
}
}
};
The API will not allow me to just do a: newAction.Parameters.Parameter.Add(actionParameter) or the like. Anyone got any ideas?
So first things, you cannot declare a foreach block inside an object instantiating scope block. What you need to do is declare a variable before, in the function scope and then attribute the Parameter property to it. Like so:
var actionParameters = new List<ActionParameter>();
foreach (ActionParameter actionParameter in actionParameterList)
{
actionParameters.Add(new ActionParameter { Name = actionParameter.Name, Value = actionParameter.Value });
}
NewActionConfiguration newAction = new NewActionConfiguration
{
Name = xmlPrimaryAction["Name"].InnerText,
TemplateToken = xmlPrimaryAction["ActionTemplate"].InnerText,
Parameters = actionParameters.ToArray()//Use System.Linq here to convert the list into an array
};
Found it! Thanks for the help #Vitor you were close but learned how to cast my list as my object after i found this: Convert List to object[]
Here's what finally worked:
var actionParameterList = new List<ActionParameter>();
foreach (XmlNode xmlParameter in xmlActionParameters)
{
ActionParameter actionParameter = new ActionParameter();
actionParameter.Name = xmlParameter["Name"].InnerText;
actionParameter.Value = xmlParameter["Value"].InnerText;
actionParameterList.Add(new ActionParameter { Name = actionParameter.Name, Value = actionParameter.Value });
}
NewActionConfiguration newAction = new NewActionConfiguration
{
Name = xmlPrimaryAction["Name"].InnerText,
TemplateToken = xmlPrimaryAction["ActionTemplate"].InnerText,
Parameters = new ActionParameters
{
Parameter = actionParameterList.Cast<ActionParameter>().ToArray()
}
};

Start or Run ECS or Fargate Task Through the C# Client Sdk

I am trying to run or start an existing task definition within ECS but the documentation is lacking and I cant seem to find any examples online. I have hit a wall and I was wondering if anyone else has done a similar thing.
I am using the AWSSDK.ECS packages.
var request = JsonConvert.DeserializeObject<Request>(record.Sns.Message);
var task = new RunTaskRequest
{
Count = 1,
NetworkConfiguration = new NetworkConfiguration
{
AwsvpcConfiguration = new AwsVpcConfiguration
{
Subnets = new List<string>() { request.SubnetId},
SecurityGroups = new List<string>() { request.SecurityGroupId},
AssignPublicIp = AssignPublicIp.DISABLED
}
},
Cluster = request.Cluster,
LaunchType = LaunchType.FARGATE,
Overrides = new TaskOverride
{
ContainerOverrides = new List<ContainerOverride>
{
new ContainerOverride
{
Name = request.ContainerName,
Environment = request.EnvironmentVariables
.Select(kvp => new Amazon.ECS.Model.KeyValuePair()
{
Name = kvp.Key,
Value = kvp.Value
}).ToList()
}
}
},
TaskDefinition = request.TaskDefinitionUri
};
await new AmazonEcsClient().RunTaskAsync(task);
Check on your task definition. If the NetworkMode is awsvpc, then you must provide NetworkConfiguration parameter. This works for me:
var runTaskRequest = new ECSModel.RunTaskRequest
{
Cluster = "cluster-name",
Count = 1,
LaunchType = LaunchType.FARGATE,
TaskDefinition = "task-definition",
NetworkConfiguration = new ECSModel.NetworkConfiguration
{
AwsvpcConfiguration = new ECSModel.AwsVpcConfiguration
{
SecurityGroups = new List<string> { "security-group" },
Subnets = new List<string> { "subnet" }
}
},
Overrides = new ECSModel.TaskOverride
{
ContainerOverrides = new List<ECSModel.ContainerOverride>
{
new ECSModel.ContainerOverride
{
Name = "container-name",
Command = new List<string>
{
// In case if you need to pass parameters to your instance:
"parameter-one", "parameter-two", "etc"
}
}
}
}
};
await new AmazonEcsClient().RunTaskAsync(runTaskRequest);

ODataComplexValue Actions and Casting

So I'm new to OData and I'm using Simple.OData.Client
So my code first looked like this :
var context = new ODataClient("http://localhost:51861/API/");
var test = context.For<Account>()
.Key("00010017")
.Action("Testing")
.Set(new Entry() { { "MyTest", New Test() { Item = "Hello World"} } })
.ExecuteAsScalarAsync<Test>()
.Result;
Leads to the following error:
"The value for parameter 'MyTest' is of type 'ODataExample.Model.MyTest'. WriteValue can only write null, ODataComplexValue, ODataEnumValue and primitive types that are not Stream type."
Ok, cool, so the exception above is informative and I can work with this by doing
ODataComplexValue MyTest = new ODataComplexValue();
ODataProperty myP = new ODataProperty();
myP.Name = "Item";
myP.Value = "Hello World";
myCustomer.TypeName = "ODataExample.Model.MyTest";
myCustomer.Properties = new[] { myP };
So now if I pass myTest into the .Set I get a working call to my OData server
.Set(new Entry() { { "MyTest", MyTest )
So Obviously I can create a ODataComplexValue with something like
var tt = new ODataComplexValue()
{
TypeName = t.GetType().FullName,
Properties = s.GetType().GetProperties().Select<PropertyInfo,ODataProperty>(x => new ODataProperty { Name = x.Name, Value = x.GetValue(t) })
};
The above works great and I an just create an extension method from that to have
.Set(new Entry() { { "MyTest", New Test() { Item = "Hello World"} } }.ToOData())
However, I can't help but feel I'm missing something, if the solution is this simple, why is Simple.OData.Client not just doing this for me? Is is there already an extension method or utility I should be using to get the same above result.
Just incase its required my webapi routing is as followed :
var function = builder.EntityType<Account>().Action("Testing");
function.Namespace = "Transaction";
function.Parameter<Test>("MyTest");
function.ReturnsFromEntitySet<Test>("Test");

Categories