更改c#Web引用URL地址

时间:2013-07-17 10:54:59

标签: c# web-services soap sqlanywhere sybase-asa

您好, 我有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。在不更改它的情况下,我的方法不会返回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数据库生成。是否有可能改变它的动态?为什么需要相同的工作?

1 个答案:

答案 0 :(得分: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;
    }

然后在你的代理类中用你的CustomSoapHttpClientProtocol替换SoapHttpClientProtocol。