在我的web应用程序中,我使用了来自同一提供程序的几个asmx(Web服务),它们有一个用于此目的,其他用于此目的,但都需要SOAP Header与认证。在C#中使用DS创建一个“all-in-one”函数
这是简单的添加验证:
public static SoCredentialsHeader AttachCredentialHeader()
{
SoCredentialsHeader ch = new SoCredentialsHeader();
ch.AuthenticationType = SoAuthenticationType.CRM5;
ch.UserId = "myUsername";
ch.Secret = apUtilities.CalculateCredentialsSecret(
SoAuthenticationType.CRM5, apUtilities.GetDays(), "myUsername", "myPassword");
return ch;
}
问题是这样的SoCredentialsHeader到来(偏差)从ONE web服务,我需要将相同的代码添加到其他人,如:
public static wsContact.SoCredentialsHeader AttachContactCredentialHeader()
{
wsContact.SoCredentialsHeader ch = new wsContact.SoCredentialsHeader();
ch.AuthenticationType = wsContact.SoAuthenticationType.CRM5;
ch.UserId = "myUsername";
ch.Secret = apUtilities.CalculateCredentialsSecret(
wsContact.SoAuthenticationType.CRM5, apUtilities.GetDays(), "myUsername", "myPassword");
return ch;
}
public static wsDiary.SoCredentialsHeader AttachDiaryCredentialHeader()
{
wsDiary.SoCredentialsHeader ch = new wsDiary.SoCredentialsHeader();
ch.AuthenticationType = wsDiary.SoAuthenticationType.CRM5;
ch.UserId = "myUsername";
ch.Secret = apUtilities.CalculateCredentialsSecret(
wsDiary.SoAuthenticationType.CRM5, apUtilities.GetDays(), "myUsername", "myPassword");
return ch;
}
有没有一种方法来实现设计模式,以便只使用一个功能但适合所有web服务?
有时我看到T字母,这是一种情况吗?如果是的话,我该如何完成这样的功能?
P.S.我可以通过枚举并使用开关来检查枚举名称并应用正确的Header,但是每次我需要添加新的WebService时,我需要添加枚举和代码,我正在为此搜索高级技术。
谢谢。
我会给这个尝试,我会搜索更多关于T4模板:) – balexandre 2009-01-04 18:59:59