2

嗨,我有 2 个客户端和 2 个不同的服务器。生成 wsdl 类后,我在 SoapHttpClientProtocol 构造函数中相应地更改客户端的 url 地址。

this.Url = "http://10.0.3.5:88/SomeName/dish

this.Url = "http://192.168.20.5:88/SomeOtherName/dish

但我无法在运行时更改 SoapDocumentMethodAttribute。如果不更改它,我的方法不会返回 DataSet 只是 null。更改属性中的所有地址后,一切正常。

[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 数据库生成。是否可以动态更改它?什么需要相同才能起作用?

4

1 回答 1

0

创建一个 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。

于 2015-11-05T19:41:56.797 回答