【发布时间】:2017-06-22 13:30:46
【问题描述】:
我有一个带有 TestService.TestServiceWebClient 类的 DLL。
它的构造函数有两个参数,一个是string类型,另一个是TestService.TestServiceWebClient.MODE类型,它是一个枚举。
在 C# 中,我可以通过下面的代码轻松使用它。
string secret;
secret = "asdfasdf";
TestService.TestServiceWebClient test = new TestService.TestServiceWebClient(secret, TestService.TestServiceWebClient.MODE.TEST);
test.setGroupForCustomer("test@foo.com", "12345", "TestService.TestServiceWebClient.CUST_GROUPS.MILITARY);
在 AX 中,我遇到了一些麻烦。我知道正确引用了 DLL,因为我在创建类的实例时看到了参数,但是我收到了诸如
之类的错误TestService 类不包含此功能
当我使用关键字new时:
TestService test;
;
test = new TestService.TestServiceWebClient(secret, "");
我也试过了……
TestService.TestServiceWebClient test;
;
test = new TestService.TestServiceWebClient(secret, "");
第二个参数不是string,所以当我尝试添加枚举时,我得到了
枚举不存在...
TestService test;
;
test = new TestService.TestServiceWebClient(secret, TestService.TestServiceWebClient.MODE::TEST);
我是否需要在 AX 中创建一个可以映射到我的 DLL 中的枚举的枚举?
C#代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Collections.Specialized;
namespace ProductService
{
public class TestWebClient
{
public enum CUST_GROUPS
{
NOT_LOGGED_IN,
GENERAL,
WHOLESALE,
RETAILER,
TEST_REVIEWS,
COTM_DISCOUNT,
MILITARY,
FIRST_RESPONDER
};
public enum MODE
{
DEV,
TEST,
PROD
}
public static int COTM_GROUP_ID = 5;
public static int GENERAL_GROUP_ID = 1;
private string presharedSecret;
private string BASE_URL;
private static string destinationPathPut = "/path";
private static string destinationPathGet = "/pathgroup";
public TestWebClient(String presharedSecret, MODE mode)
{
this.presharedSecret = presharedSecret;
switch (mode)
{
case MODE.DEV:
BASE_URL = "http://dev";
break;
case MODE.TEST:
BASE_URL = "http://test";
break;
case MODE.PROD:
BASE_URL = "https://prod";
break;
}
}
public bool setGroupForCustomer(string customerEmail, string customerId, CUST_GROUPS selectedGroup)
{
WebClient client = new WebClient();
try
{
NameValueCollection requestParams = new NameValueCollection();
requestParams.Add("customer_id", customerId);
requestParams.Add("email", customerEmail);
requestParams.Add("group_id", ((int)selectedGroup).ToString());
requestParams.Add("signature", Util.sha1Hash(customerId.ToString() + ((int)selectedGroup).ToString() + customerEmail + presharedSecret));
byte[] response = client.UploadValues(BASE_URL + "/" + destinationPathPut,
requestParams
);
string result = System.Text.Encoding.UTF8.GetString(response);
}
catch (Exception e)
{
return false;
}
finally
{
client.Dispose();
}
return true;
}
public bool isInGroup(string customerEmail, string customerId, CUST_GROUPS selectedGroup)
{
WebClient client = new WebClient();
NameValueCollection requestParams = new NameValueCollection();
requestParams.Add("customer_id", customerId);
requestParams.Add("email", customerEmail);
requestParams.Add("group_id", ((int)selectedGroup).ToString());
requestParams.Add("signature", Util.sha1Hash(customerId.ToString() + ((int)selectedGroup).ToString() + customerEmail + presharedSecret));
byte[] response = client.UploadValues(BASE_URL + "/" + destinationPathGet,
requestParams
);
string result = System.Text.Encoding.UTF8.GetString(response);
client.Dispose();
System.Diagnostics.Debug.WriteLine(result);
return result.Equals("true");
}
}
}
【问题讨论】:
标签: .net axapta dynamics-ax-2009