在验证我的wcf服务中的凭据(如AX服务器域,用户名和密码)后,Dowmload Microsoft Dynamics AX 2012服务wsdl元数据

问题描述 投票:0回答:1

我完全不熟悉此Microsoft Dynamics AX 2012工具和WCF服务。我有一个自我托管的WCF服务,该服务将AX 2012服务wsdl URL,AX服务器域名,用户名和密码作为输入,并尝试在没有任何用户身份验证机制的情况下下载此wsdl url的元数据。

下面的[MY AX 2012服务WSDl URL:http://####:8##1/DynamicsAx/Services/TestService?wsdl---> WSDLEndpoint

我正在动态创建WSHttpBinding,MetadataExchangeClient,并分配了所有属性并传递了wsdl端点。

下面是我的示例代码:

var binding = new WSHttpBinding(SecurityMode.None) { MaxReceivedMessageSize = int.MaxValue, MaxBufferPoolSize = int.MaxValue };
var mexClient = new MetadataExchangeClient(binding)
{
    ResolveMetadataReferences = true,
    MaximumResolvedReferences = int.MaxValue,
    OperationTimeout = TimeSpan.FromSeconds(TimeOutInSeconds),
    HttpCredentials =
                            new NetworkCredential(Username, Password, Domain)
};
mexClient.GetMetadata(new Uri(WSDLEndpoint), MetadataExchangeClientMode.HttpGet);
Log.Info("Metadata successfully downloaded.");      

但是上面的代码不会打扰用户凭证验证,它直接从WSDL URL中下载元数据,但是我希望验证用户凭证,并且在成功认证之后,将下载元数据。

[请提供一些身份验证方法来帮助我,以在支持跨平台的wshttpbinding之上进行介绍。

c# wcf authentication axapta dynamics-ax-2012
1个回答
0
投票

我不完全理解你的意思。您是否要使用自定义用户名/密码身份验证创建WCF服务?这要求我们在服务器端配置证书。我创建了一个示例,希望它对您有帮助。服务器端。

class Program
    {
        static void Main(string[] args)
        {
            Uri uri = new Uri("http://localhost:21011");
            WSHttpBinding binding = new WSHttpBinding();
            binding.Security.Mode = SecurityMode.Message;
            binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;

            using (ServiceHost sh = new ServiceHost(typeof(MyService), uri))
            {
                sh.AddServiceEndpoint(typeof(IService), binding, "");
                ServiceMetadataBehavior smb;
                smb = sh.Description.Behaviors.Find<ServiceMetadataBehavior>();
                if (smb == null)
                {
                    smb = new ServiceMetadataBehavior()
                    {
                        HttpGetEnabled = true

                    };
                    sh.Description.Behaviors.Add(smb);
                }
                sh.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByThumbprint, "5ba5022f527e32ac02548fc5afc558de1d314cb6");

                Binding mexbinding = MetadataExchangeBindings.CreateMexHttpBinding();
                sh.AddServiceEndpoint(typeof(IMetadataExchange), mexbinding, "mex");

                sh.Opened += delegate
                {
                    Console.WriteLine("Service is ready");
                };
                sh.Closed += delegate
                {
                    Console.WriteLine("Service is clsoed");
                };
                sh.Open();
                Console.ReadLine();
                //pause
                sh.Close();
                Console.ReadLine();
            }
        }
    }
    [ServiceContract]

    public interface IService
    {
        [OperationContract]
        string Test();

    }
    public class MyService : IService
    {
        public string Test()
        {

            return DateTime.Now.ToString();
        }

}

在客户端,我们通过添加服务引用来创建客户端代理。

ServiceReference1.ServiceClient client = new ServiceClient();
            client.ClientCredentials.UserName.UserName = "administrator";
            client.ClientCredentials.UserName.Password = "abcd1234!";
            var result = client.Test();
            Console.WriteLine(result);

在客户端自动生成的配置。

  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IService">
          <security>
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://10.157.13.69:21011/" binding="wsHttpBinding"
        bindingConfiguration="WSHttpBinding_IService" contract="ServiceReference1.IService"
        name="WSHttpBinding_IService">
        <identity>
          <certificate encodedValue="blabla… " />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>

在上面的示例中,客户端应提供要由服务器验证的用户名/密码,以便调用远程服务。https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/message-security-with-a-user-name-client请随时告诉我是否有什么我可以帮助的。

© www.soinside.com 2019 - 2024. All rights reserved.