locked
Request.ServerVariables variables seems to be established with the first request to my asmx WS RRS feed

  • Question

  • I have an asmx WS, in which I have implemented an override of the "ReflectMethod" of "SoapExtensionReflector" to modify the WSDL response of the WS, concretely the location in this point of the WSDL definition:

    <wsdl:service name="SGTEstimate">
    <wsdl:port name="SGTEstimateSoap" binding="tns:SGTEstimateSoap">
    <soap:address location="https://XXXXXXXXXXXXXXX/SGTEstimate.asmx?WSDL"/>
    </wsdl:port>

    The case is that we are using the next code to do it:

    public class Reflector : SoapExtensionReflector
        {

            public override void ReflectMethod()
            {

                ServiceDescription sd = ReflectionContext.ServiceDescription;

                ServiceCollection myServiceCollection = sd.Services;

                foreach (Port port in myServiceCollection[0].Ports)
                {
                    foreach (ServiceDescriptionFormatExtension extension in port.Extensions)
                    {
                        if (extension is SoapAddressBinding)
                        {

                            SoapAddressBinding address = (SoapAddressBinding)extension;
                            IServiceProvider serviceProvider = (IServiceProvider)HttpContext.Current;
                            HttpWorkerRequest workerRequest = (HttpWorkerRequest)serviceProvider.GetService(typeof(HttpWorkerRequest));
                            string realUrl = workerRequest.GetServerVariable("HTTP_URL");
                            string server = workerRequest.GetServerVariable("HTTP_X_FORWARDED_HOST");
                            NameValueCollection appSettings = ConfigurationManager.AppSettings;
                            string protocol = appSettings["protocol"].ToString();
                           

                            if ((server == (string.Empty)) || (server == null))
                                server = workerRequest.GetServerVariable("HTTP_X_FORWARDED_SERVER");

                            if ((server == (string.Empty)) || (server == null))
                                server = appSettings["server"].ToString();

                            if ((realUrl == (string.Empty)) || (realUrl == null))
                                realUrl = appSettings["realUrl"].ToString();


                            address.Location = String.Concat(protocol, "://", server, realUrl);
                            


                        }
                    }
                }
            }

    and this WS can be accesed from 2 urls("yyyyyy.com\SGtEstimate.asmx" and "XXXXXX.com\SGtEstimate.asmx"), and if you reset the IIS and you do the first request using  "yyyyyy.com\SGtEstimate.asmx", all times you access to this service using "yyyyyy.com" or  "XXXXXX.com" in the WSDL definition it allways show "yyyyyy.com\SGtEstimate.asmx", and if I reset the IIS and I do the first access using "XXXXXX.com\SGtEstimate.asmx" all next times I access using  "yyyyyy.com" or  "XXXXXX.com" it shows in the WSDL definition "XXXXXXX.com". This information seems to be cached.

    I tried setting in the IISS "Enable content expiration"="Inmediately" and setting "CacheDuration" to the methods to "0" it doesn´t fix the problem.

    Someone can help me?

    • Moved by Bob Shen Friday, November 9, 2012 6:49 AM (From:Visual C# General)
    Thursday, November 8, 2012 5:25 PM

All replies

  • Hi rlagares,

    According to your description, I'd like to move this thread to ASMX Web Services and XML Serialization Forum for better support, where more experts live.
     
    Thanks for your understanding.


    Bob Shen [MSFT]
    MSDN Community Support | Feedback to us

    Friday, November 9, 2012 6:48 AM
  • This functionality is used very rarely. I've never used it.

    Are you aware that the location in the WSDL is meant to be a hint only? The client should set the actual URL to the service on its own.


    John Saunders
    WCF is Web Services. They are not two separate things.
    Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
    Use File->New Project to create Web Service Projects

    Monday, November 12, 2012 7:11 PM
    Moderator