问题描述
我访问一个Web服务,它提供了一个方法 ProcessMessage的
这个方法如下:
< System.Web.Services.Protocols.SoapHeaderAttribute(payloadManifest方向:= System.Web.Services.Protocols.SoapHeaderDirection.InOut),_
System.Web.Services.Protocols.SoapDocumentMethodAttribute(\"http://exampleurl/operations/ProcessMessage/v1_01/GetTest1\" &安培; _
RequestNamespace:=HTTP:// EXAMPLEURL,ResponseNamespace:=HTTP:// EXAMPLEURL,用途:= System.Web.Services.Description.SoapBindingUse.Literal,ParameterStyle:= System.Web.Services.Protocols .SoapParameterStyle.Wrapped)GT; _
公用Sub ProcessMessage的(为ByRef载荷的有效载荷)
尝试
昏暗的结果()为对象= Me.Invoke(ProcessMessage的新的对象(){}有效载荷)
有效载荷= CTYPE(结果(0),有效载荷)
昏暗我为整数= 0
抓住EX为例外 结束Try
结束小组
此工作正常,但是,这种方法是可用于各种不同的功能。如果 SoapDocumentMethodAttribute
动作
更改 ProcessMessage的
返回的值不同。
例如:
修改
<$p$p><$c$c>System.Web.Services.Protocols.SoapDocumentMethodAttribute(\"http://exampleurl/operations/ProcessMessage/v1_01/GetTest1\"要
<$p$p><$c$c>System.Web.Services.Protocols.SoapDocumentMethodAttribute(\"http://exampleurl/operations/ProcessMessage/v1_01/GetTest2\"现在的问题是,据我所看到的,这个动作
必须是硬coded到文件,因此我只能运行1方法每个编译的程序。是否有动态变化的任何方式动作
或者我应该进行不同的处理这个?
好,我找到了一个解决办法,但它不完全理想。基本上,我们设置这个属性来填充的SOAPAction
头。但是,我们决定改变的SOAPAction
头直接而不是通过属性。要简单得多,但肯定是一个黑客-Y方法。
I am accessing a web service which provides a single method ProcessMessage
this method looks like:
<System.Web.Services.Protocols.SoapHeaderAttribute("payloadManifest", Direction:=System.Web.Services.Protocols.SoapHeaderDirection.InOut), _
System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://exampleurl/operations/ProcessMessage/v1_01/GetTest1" & _
"", RequestNamespace:="http://exampleurl", ResponseNamespace:="http://exampleurl", Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)> _
Public Sub ProcessMessage(ByRef payload As Payload)
Try
Dim results() As Object = Me.Invoke("ProcessMessage", New Object() {payload})
payload = CType(results(0), Payload)
Dim i As Integer = 0
Catch ex As Exception
End Try
End Sub
This works fine, however, this method is to be used for various different functions. If the SoapDocumentMethodAttribute
Action
is changed ProcessMessage
returns different values.
Example:
Change
System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://exampleurl/operations/ProcessMessage/v1_01/GetTest1"
To
System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://exampleurl/operations/ProcessMessage/v1_01/GetTest2"
Now the problem is, as far as I can see, this Action
needs to be hard-coded into the file and therefore I can only run 1 method with each compiled program. Is there any way of dynamically changing the Action
or should I be approaching this differently?
Ok I found a workaround, but it's not exactly ideal. Basically, we were setting this attribute to populate the SOAPAction
header. But we decided to change the SOAPAction
header directly rather than through the attributes. Much simpler but surely a hack-y method.
这篇关于动态改变属性的性质的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!