我们的机器有多个IP地址,服务器只接受来自一个特定IP地址的请求。我正在寻找一种从特定IP地址发送SOAP请求的方法。
此问题是对this one的扩展,但它适用于网络参考,我使用服务参考。
我正在使用Visual Studio 2013.它从WSDL生成代理类,看起来它使用WCF / ServiceModel来发送请求。
为客户端生成的代理类如下所示:
<System.Diagnostics.DebuggerStepThroughAttribute(), _
System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")> _
Partial Public Class TestActivitySoapClient
Inherits System.ServiceModel.ClientBase(Of Consoto.TestActivitySoap)
Implements Consoto.TestActivitySoap
Public Sub New()
MyBase.New()
End Sub
Public Sub New(ByVal endpointConfigurationName As String)
MyBase.New(endpointConfigurationName)
End Sub
Public Sub New(ByVal endpointConfigurationName As String, ByVal remoteAddress As String)
MyBase.New(endpointConfigurationName, remoteAddress)
End Sub
Public Sub New(ByVal endpointConfigurationName As String, ByVal remoteAddress As System.ServiceModel.EndpointAddress)
MyBase.New(endpointConfigurationName, remoteAddress)
End Sub
Public Sub New(ByVal binding As System.ServiceModel.Channels.Binding, ByVal remoteAddress As System.ServiceModel.EndpointAddress)
MyBase.New(binding, remoteAddress)
End Sub
<System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)> _
Function Consoto_TestActivitySoap_TestActivity(ByVal request As Consoto.TestActivityRequest) As Consoto.TestActivityServiceResponse Implements Consoto.TestActivitySoap.TestActivity
Return MyBase.Channel.TestActivity(request)
End Function
Public Function TestActivity(ByVal TestActivity1 As Consoto.TestActivity) As Consoto.TestActivityResponse
Dim inValue As Consoto.TestActivityRequest = New Consoto.TestActivityRequest()
inValue.TestActivity = TestActivity1
Dim retVal As Consoto.TestActivityServiceResponse = CType(Me, Consoto.TestActivitySoap).TestActivity(inValue)
Return retVal.TestActivityResponse
End Function
<System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)> _
Function Consoto_TestActivitySoap_TestActivityAsync(ByVal request As Consoto.TestActivityRequest) As System.Threading.Tasks.Task(Of Consoto.TestActivityServiceResponse) Implements Consoto.TestActivitySoap.TestActivityAsync
Return MyBase.Channel.TestActivityAsync(request)
End Function
Public Function TestActivityAsync(ByVal TestActivity As Consoto.TestActivity) As System.Threading.Tasks.Task(Of Consoto.TestActivityServiceResponse)
Dim inValue As Consoto.TestActivityRequest = New Consoto.TestActivityRequest()
inValue.TestActivity = TestActivity
Return CType(Me, Consoto.TestActivitySoap).TestActivityAsync(inValue)
End Function
End Class
我尝试覆盖CreateChannel
Protected Overrides Function CreateChannel() As TestActivitySoap
Return MyBase.CreateChannel()
End Function
但无法弄清楚我应该写些什么。
此外,我无法找到一种方法来覆盖System.ServiceModel.ClientBase的行为以指定local EndPoint,并且我可以对任何.NET语言中的所有建议开放。如果无法做到这一点,请提出另一种方法来实现这一目标。