How to Consume ActionService.wsdl into Dot Net 8.0 #800
Replies: 2 comments
-
This automatically generated reply acts as a friendly reminder. Answers to your questions will most often come from the community, from developers like yourself. You will, from time to time, find that Axis employees answers some of the questions, but this is not a guarantee. Think of the discussion forum as a complement to other support channels, not a replacement to any of them. If your question remains unanswered for a period of time, please revisit it to see whether it can be improved by following the guidelines listed in Axis support guidelines. |
Beta Was this translation helpful? Give feedback.
-
Hi @rohitmanchanda02 , dotnet-svcutil still not support the .NET 8.0: Reference: Support net8 SDK in dotnet-svcutil #5376 As per my understanding, there is no sample available from Axis using Event and action services APIs with .NET core 8.0. Alternative:You can use the XML as a Body and send it as a REST API call. Sample code:using RestSharp;
using System;
using System.Security.Cryptography;
using System.Text;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Xml;
class Program
{
#pragma warning disable CS8604 // Possible null reference argument for parameter 'source'
#pragma warning disable CS8603 // Possible null reference return
static async Task Main(string[] args)
{
var client = new RestClient("http://10.176.12.84");
var request = new RestRequest("/vapix/services", Method.Post);
// Get the digest authentication header
string digestHeader = await GetDigestHeader(client, "root", "pass", "/vapix/services");
if (string.IsNullOrEmpty(digestHeader))
{
Console.WriteLine("Failed to generate Digest Authentication header.");
return;
}
request.AddHeader("Authorization", digestHeader);
// XML body for the SOAP request
string xmlBody = @"<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope' xmlns:act='http://www.axis.com/vapix/ws/action1'>
<soap:Header/>
<soap:Body>
<act:GetActionRules/>
</soap:Body>
</soap:Envelope>";
request.AddParameter("application/xml", xmlBody, ParameterType.RequestBody);
// Execute the request
var response = await client.ExecuteAsync(request);
if (response.IsSuccessful)
{
Console.WriteLine(FormatXml(response.Content));
}
else
{
Console.WriteLine($"Request failed with status code: {response.StatusCode}, Content: {response.Content}");
}
}
static string FormatXml(string xml)
{
var doc = new XmlDocument();
doc.LoadXml(xml);
StringWriter stringWriter = new StringWriter();
using (XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter))
{
xmlTextWriter.Formatting = Formatting.Indented; // Set formatting to indented
doc.WriteTo(xmlTextWriter);
}
return stringWriter.ToString();
}
public static async Task<string> GetDigestHeader(RestClient client, string username, string password, string path)
{
// First request to get the digest challenge
var request = new RestRequest(path, Method.Get);
var response = await client.ExecuteAsync(request);
if (response.StatusCode == HttpStatusCode.Unauthorized)
{
var wwwAuthenticateHeader = response.Headers.FirstOrDefault(h => h.Name.Equals("WWW-Authenticate", StringComparison.OrdinalIgnoreCase))?.Value?.ToString();
if (string.IsNullOrEmpty(wwwAuthenticateHeader))
{
Console.WriteLine("No WWW-Authenticate header found.");
return null;
}
// Log the raw WWW-Authenticate header for debugging
Console.WriteLine("WWW-Authenticate Header: " + wwwAuthenticateHeader);
// Parse the WWW-Authenticate header to extract values
var digestHeader = ParseDigestHeader(wwwAuthenticateHeader);
// Log parsed values for debugging
Console.WriteLine("Parsed Digest Header: ");
foreach (var entry in digestHeader)
{
Console.WriteLine($"{entry.Key}: {entry.Value}");
}
if (!digestHeader.ContainsKey("nonce"))
{
Console.WriteLine("Digest header does not contain 'nonce'. Check the authentication response.");
return null;
}
// Generate the Digest Authentication response
string ha1 = CreateMD5($"{username}:{digestHeader["realm"]}:{password}");
string ha2 = CreateMD5($"POST:{path}");
string responseHash = CreateMD5($"{ha1}:{digestHeader["nonce"]}:00000001:{digestHeader["cnonce"]}:auth:{ha2}");
// Check if "opaque" exists in the digestHeader dictionary
string opaque = digestHeader.ContainsKey("opaque") ? $", opaque=\"{digestHeader["opaque"]}\"" : "";
// Build the Digest Authentication header
string authHeader = $"Digest username=\"{username}\", realm=\"{digestHeader["realm"]}\", nonce=\"{digestHeader["nonce"]}\", uri=\"{path}\", " +
$"qop=auth, nc=00000001, cnonce=\"{digestHeader["cnonce"]}\", response=\"{responseHash}\"{opaque}";
return authHeader;
}
return null;
}
private static Dictionary<string, string> ParseDigestHeader(string wwwAuthenticateHeader)
{
var headerValues = new Dictionary<string, string>();
// Remove 'Digest ' part and split the remaining by commas
var parts = wwwAuthenticateHeader.Replace("Digest ", "").Split(',');
foreach (var part in parts)
{
// Split each key-value pair by the first '=' character
var keyValue = part.Split(new[] { '=' }, 2);
if (keyValue.Length == 2)
{
var key = keyValue[0].Trim(); // Trim spaces
var value = keyValue[1].Trim(' ', '"'); // Trim spaces and quotes from value
headerValues[key] = value;
}
}
// Add a cnonce value (client nonce)
headerValues["cnonce"] = CreateMD5(DateTime.Now.Ticks.ToString());
return headerValues;
}
private static string CreateMD5(string input)
{
using (var md5 = MD5.Create())
{
var inputBytes = Encoding.ASCII.GetBytes(input);
var hashBytes = md5.ComputeHash(inputBytes);
var sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("x2"));
}
return sb.ToString();
}
}
#pragma warning restore CS8604
#pragma warning restore CS8603
}
Output: |
Beta Was this translation helpful? Give feedback.
-
How to consume ActionService.wsdl into Dot net 8.0 .
I have been trying to consume ActionService.wsdl into Dot net 8.0
Since,there is no System.Web.Service reference present in .NET 8.0
The proxy class doesn't generate any actionbinding class like it did for Framework 4.7.1
http://www.axis.com/vapix/ws/action1/ActionService.wsdl
Beta Was this translation helpful? Give feedback.
All reactions