ASMX Web 服务 Soap 扩展 - 如何将属性注入客户端代理类?
我尝试在客户端设置肥皂扩展属性。例如:
Web 服务中的实现:
[AttributeUsage(AttributeTargets.Method)]
public class EncryptMessageAttribute : SoapExtensionAttribute
{
private string strKey="null";
public string StrKey
{
get { return strKey; }
set { strKey = value; }
}
}
Soap 扩展类:
public class EncryptMessage : SoapExtension
{
...
}
用于 Web 方法:
[WebMethod]
[EncryptMessage( StrKey = "pass")]
public string test2()
{
return "ok";
}
Proxy 类中的实现:
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/test", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[EncryptMessage( StrKey = "pass")]
public string test() {
object[] results = this.Invoke("test", new object[0]);
return ((string)(results[0]));
}
Soap 扩展属性为::[EncryptMessage( StrKey = "pass")]
我想设置 Soap客户端的扩展属性,在我使用 Soap Extension 之前,当我调用一些 Web 方法时。
示例:我调用一些方法,在使用肥皂扩展之前在两侧设置肥皂扩展属性。有人可以帮助我吗?
I try set soap extension attributes on client side. For example:
Implementation in web service:
[AttributeUsage(AttributeTargets.Method)]
public class EncryptMessageAttribute : SoapExtensionAttribute
{
private string strKey="null";
public string StrKey
{
get { return strKey; }
set { strKey = value; }
}
}
Soap extension class:
public class EncryptMessage : SoapExtension
{
...
}
Used on web method:
[WebMethod]
[EncryptMessage( StrKey = "pass")]
public string test2()
{
return "ok";
}
Implementation in Proxy class:
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/test", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[EncryptMessage( StrKey = "pass")]
public string test() {
object[] results = this.Invoke("test", new object[0]);
return ((string)(results[0]));
}
Soap extension attributes are::[EncryptMessage( StrKey = "pass")]
I want to set Soap Extension Attribute on client side, before than I use Soap Extension, when I call some web methods.
Example: I call some method, wich set soap extension attributes on both side, before than soap extension is used. Can somebody help me ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,如果您可以使用 WCF 来实现此目的,那么您应该这样做。微软表示ASMX Web服务是“遗留技术”,所有新的Web服务开发都应该使用WCF。
无论如何,请参阅 SoapExtensionReflector 和 SoapExtensionImporter 类。请注意,这些仅适用于 .NET、ASMX 客户端。
First of all, if you can use WCF for this, then you should. Microsoft has stated that ASMX web services are "legacy technology", and that all new web service development should use WCF.
In any case, see the SoapExtensionReflector and SoapExtensionImporter classes. Note that these will only work for .NET, ASMX clients.