你好, 我有 2 个客户端和 2 个不同的服务器。 生成 wsdl 类后,我在 SoapHttpClientProtocol consructor 中相应地更改客户端的 url 地址。
来自
this.Url = "http://10.0.3.5:88/SomeName/dish
到
this.Url = "http://192.168.20.5:88/SomeOtherName/dish
但我无法在运行时更改 SoapDocumentMethodAttribute。如果不更改它,我的方法不会只返回 null 的 DataSet。更改属性中的所有地址后,一切正常。
[System.Web.Services.Protocols.SoapDocumentMethodAttribute( "http://10.0.3.5:88/SomeName/EuroSoft/ProductTransferExecute", RequestNamespace = "http://10.0.3.5:88/SomeName/dish", ResponseNamespace = "http://10.0.3.5:88/SomeName/dish", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle =
System.Web.Services.Protocols.SoapParameterStyle.Wrapped )]
public System.Data.DataSet ProductTransferExecute( [System.Xml.Serialization.XmlElementAttribute( IsNullable = true )] string department, [System.Xml.Serialization.XmlElementAttribute( IsNullable = true )] string XMLproducts, out int sqlcode ) {}
服务由 Sybase Anywhere 9 数据库生成。是否可以动态更改它?什么需要完全相同才能起作用?
最佳答案
创建一个 CustomSoapHttpClientProtocol:
public class CustomSoapHttpClientProtocol : SoapHttpClientProtocol
{
public string SoapActionUrl { get; private set; }
public CustomSoapHttpClientProtocol(string soapActionUrl)
{
this.SoapActionUrl = soapActionUrl;
}
protected override WebResponse GetWebResponse(WebRequest request)
{
const string soapAction = "SOAPAction";
if (request.Headers.Count > 0 && request.Headers.AllKeys.Contains(soapAction))
{
request.Headers[soapAction] = SoapActionUrl;
}
WebResponse response = base.GetWebResponse(request);
return response;
}
然后在您的代理类中将 SoapHttpClientProtocol 替换为您的 CustomSoapHttpClientProtocol。
关于c# - 更改c# WebReference url地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17697900/