2

Hi, I have 2 clients with 2 different servers. After generating wsdl classes I change url address for clients accordingly in SoapHttpClientProtocol consructor.

from

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

to

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

But I can't change SoapDocumentMethodAttribute at runtime. Without changing it my method doesn't return DataSet just null. After changing all addresses in attribute everything works fine.

[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 ) {}

Services are generated by Sybase Anywhere 9 database. Is it possible to change it dynamic? What needs to be identical for this to work?

koziol
  • 21
  • 2
  • I thing it's problem with SOAPAction in wsdl that changes with servers. I'll try this solution [link](http://social.msdn.microsoft.com/Forums/vstudio/en-US/0e9874a5-ce16-4d69-936c-4af46d6a02a2/soap-action-override-at-runtime-from-imported-wsdl) – koziol Jul 18 '13 at 08:35
  • Another similar problem [stack link](http://stackoverflow.com/questions/8504820/dynamically-changing-attributes-for-properties) – koziol Jul 18 '13 at 09:01

1 Answers1

0

Create a 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;
    }

Then in your proxy class replace SoapHttpClientProtocol with your CustomSoapHttpClientProtocol.

Elton Santana
  • 950
  • 3
  • 11
  • 22