无法发布到 AXL 终结点



我的目标是能够从使用基于 SOAP 的 API 的端点发布和检索


我的项目结构

我用 WSDL 文件生成了一个客户端来定位 cucm 11.5,然后

我按照 github 上的示例创建了所有类和接口,就像在存储库中所做的那样

第三,我的解决方案由两个项目组成,一个类库和一个控制台项目,类库包含从WSDL文件生成的客户端,控制台项目由类和接口组成,用于与类库项目交互


我有以下类来执行操作


public class TestAxl
{
public void CreateUsers()
{
var axlClient = new AxlClient(new AxlClientConfiguration
{
Server = "Ip to the publish server",
User = "administrator",
Password = "password provided"

});


var addUserResult = axlClient.ExecuteAsync(async client =>
{
var userId = Guid.NewGuid().ToString();
var request = new AddUserReq
{
user = new XUser
{
userid = userId,
userIdentity = userId,
password = "P@ssw0rd",
firstName = "test",
lastName = "test"
}
};
var response = await client.addUserAsync(request);
return response.addUserResponse1.@return;
});

}

}

我像这样从主类中调用它


class Program
{
static void Main(string[] args)
{

var letsDoSomeTesting = new TestAxl();
try
{
letsDoSomeTesting.CreateUsers();

}
catch (Exception e)
{

Console.WriteLine("The following is the exceeption from calling final class ", e.Message);
}


}

}

当我尝试运行控制台项目时,它以 0 启动和退出,

然后我回到CUCM沙箱环境,没有任何变化,此操作不起作用的可能原因是什么

仅供参考:运行时网络核心 3.1

我能够一起获得一个示例项目,包括AXL/addUser,在Linux上使用DotNet Core 3.1:https://github.com/CiscoDevNet/axl-dotnet-samples

这是主要部分:

// Create a custom binding so we can allow the client to use cookies with AXL
BasicHttpsBinding binding = new BasicHttpsBinding();
binding.AllowCookies = true;
// Specify the CUCM AXL API location for the SOAP client
EndpointAddress address = new EndpointAddress( $"https://{ System.Environment.GetEnvironmentVariable( "CUCM_ADDRESS" ) }:8443/axl/" );
//Class generated from AXL WSDL
AXLPortClient client = new AXLPortClient( binding, address );
// To disable HTTPS certificate checking, uncomment the below lines
// NOT for production use!
// client.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication
//     {
//         CertificateValidationMode = X509CertificateValidationMode.None,
//         RevocationMode = X509RevocationMode.NoCheck
//     };
// client.ChannelFactory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
// client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
// Incantation to force alternate serializer reflection behaviour due to complexities in the AXL schema
// See https://github.com/dotnet/wcf/issues/2219
MethodInfo method = typeof( XmlSerializer ).GetMethod( "set_Mode", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static );
method.Invoke( null, new object[] { 1 } ); 
// Base64 encode AXL username/password for Basic Auth
var encodedUserPass = Convert.ToBase64String( Encoding.ASCII.GetBytes( 
System.Environment.GetEnvironmentVariable( "CUCM_USERNAME" ) + ":" +
System.Environment.GetEnvironmentVariable( "CUCM_PASSWORD" )
) );
// Incantation to create and populate a Basic Auth HTTP header
// This must be done to force SoapCore to include the Authorization header on the first attempt
// rather than in challenge/response fashion
HttpRequestMessageProperty requestProperty = new HttpRequestMessageProperty();
requestProperty.Headers[ "Authorization" ] = "Basic " + encodedUserPass;
// Creating context block apparently allows attaching custom HTTP headers to the request
var scope = new OperationContextScope( client.InnerChannel );
OperationContext.Current.OutgoingMessageProperties[ HttpRequestMessageProperty.Name ] = requestProperty;
//Create the request object
AddUserReq addUserReq = new AddUserReq(); 
addUserReq.user = new XUser();
addUserReq.user.lastName = "TestUser";
addUserReq.user.userid = "testUser";
addUserReq.user.password = "Cisco!1234";
string userPkid = "";
//Try the addUser request
try
{
addUserResponse addUserResp = await client.addUserAsync( addUserReq );
userPkid = addUserResp.addUserResponse1.@return;
}
catch ( Exception ex )
{
Console.WriteLine( $"nError: addUser: { ex.Message }" );
Environment.Exit( -1 );
}

一些注意事项:

  • SoapCore 尽可能生成具有默认值的元素,例如字符串元素为 nil。 这会导致<addUser>出现问题,因为<customerName>元素只能发送到HCS CUCM。 在运行 svcutil 之前对 AXLSoap.xsd 的修改能够解决它:

    sed -i 's/name="customerName" nillable="true"/name="customerName" nillable="false"/g' schema/AXLSoap.xsd
    
  • 由于CUCM自签名证书的HTTPS认证验证,请求将失败,除非它已安装到OS CA信任存储或禁用(请参阅上面代码中的注释部分(

  • 需要以下奇怪的代码来避免在发出请求时出现"不支持编译 JScript/CSharp 脚本"错误(根据此处(:

    MethodInfo method = typeof( XmlSerializer ).GetMethod( "set_Mode", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static );
    method.Invoke( null, new object[] { 1 } );
    

最新更新