1

I have been attempting to remove a port from the URL for my web service. The web service is load balanced across multiple servers. I have the following code working correctly in Production for C#; however, for this particular project I am having to use VB. I have converted it and I am not having any compiling errors, but I am getting the following runtime error:

The value of the property 'type' cannot be parsed. The error is: Could not load type 'WebServicesSoapPortRemovalReflector' from assembly 'WebService1'.

Everything I read always references's back to this article: http://blogs.msdn.com/b/kaevans/archive/2005/11/16/493496.aspx

C# (This works, no error.)

using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web.Services.Description;
using System.Web;

namespace Webservice1
{
    /// <summary>
    /// Taken from http://blogs.msdn.com/b/kaevans/archive/2005/11/16/493496.aspx
    /// </summary>
    /// <remarks></remarks>
    public class WebServicesSoapPortRemovalReflector : SoapExtensionReflector
    {

        public override void ReflectMethod() { }

        public override void ReflectDescription()
        {
            if (bool.Parse(ConfigurationManager.AppSettings["EnableWebServicePortRemoval"]))
            {
                string portToRemove = string.Format(":{0}", ConfigurationManager.AppSettings["WebServicePortToRemove"]);
                ServiceDescription description = ReflectionContext.ServiceDescription;
                foreach (Service service in description.Services)
                {
                    foreach (Port port in service.Ports)
                    {
                        foreach (ServiceDescriptionFormatExtension extension in port.Extensions)
                        {
                            if (extension is SoapAddressBinding)
                            {
                                SoapAddressBinding binding = (SoapAddressBinding)extension;
                                if (binding != null)
                                    binding.Location = binding.Location.Replace(portToRemove, "");
                            }
                            else if (extension is Soap12AddressBinding)
                            {
                                Soap12AddressBinding binding = (Soap12AddressBinding)extension;
                                if (binding != null)
                                    binding.Location = binding.Location.Replace(portToRemove, "");
                            }
                            else if (extension is HttpAddressBinding)
                            {
                                HttpAddressBinding binding = (HttpAddressBinding)extension;
                                if (binding != null)
                                    binding.Location = binding.Location.Replace(portToRemove, "");
                            }
                        }
                    }
                }
            }
        }
    }
}

VB (Receives runtime error)

Imports System.Configuration
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web.Services.Description
Imports System.Web

Namespace WebService1
    ''' <summary>
    ''' Taken from http://blogs.msdn.com/b/kaevans/archive/2005/11/16/493496.aspx
    ''' </summary>
    ''' <remarks></remarks>
    Public Class WebServicesSoapPortRemovalReflector
        Inherits SoapExtensionReflector

        Public Overrides Sub ReflectMethod()
        End Sub

        Public Overrides Sub ReflectDescription()
            If Boolean.Parse(ConfigurationManager.AppSettings("EnableWebServicePortRemoval")) Then
                Dim portToRemove As String = String.Format(":{0}", ConfigurationManager.AppSettings("WebServicePortToRemove"))
                Dim description As ServiceDescription = ReflectionContext.ServiceDescription
                For Each service As Service In description.Services
                    For Each port As Port In service.Ports
                        For Each extension As ServiceDescriptionFormatExtension In port.Extensions
                            If TypeOf extension Is SoapAddressBinding Then
                                Dim binding As SoapAddressBinding = DirectCast(extension, SoapAddressBinding)
                                If binding IsNot Nothing Then
                                    binding.Location = binding.Location.Replace(portToRemove, "")
                                End If
                            ElseIf TypeOf extension Is Soap12AddressBinding Then
                                Dim binding As Soap12AddressBinding = DirectCast(extension, Soap12AddressBinding)
                                If binding IsNot Nothing Then
                                    binding.Location = binding.Location.Replace(portToRemove, "")
                                End If
                            ElseIf TypeOf extension Is HttpAddressBinding Then
                                Dim binding As HttpAddressBinding = DirectCast(extension, HttpAddressBinding)
                                If binding IsNot Nothing Then
                                    binding.Location = binding.Location.Replace(portToRemove, "")
                                End If
                            End If
                        Next
                    Next
                Next
            End If
        End Sub

    End Class
End Namespace

Web.config (same for both C# & VB)

<webServices>
    <soapExtensionReflectorTypes>
      <add type="WebService1.WebServicesSoapPortRemovalReflector, WebService1" />
    </soapExtensionReflectorTypes>
</webServices>

1 Answer 1

1

In VB.NET it's a bit different. The namespace is prefixed with the root namespace defined in the project's properties. That's why, if you didn't notice already, newly added classes in VB.NET do not have a default namespace (just try it).

So, assuming that root namespace is WebService1, your config should be:

<webServices>
    <soapExtensionReflectorTypes>
      <add type="WebService1.WebService1.WebServicesSoapPortRemovalReflector, WebService1" />
    </soapExtensionReflectorTypes>
</webServices>

I think this explains the behavior a bit better (also a demo).

In any case, make sure you check your own project properties and adjust the configuration accordingly.

3
  • 2
    Or remove the explicit namespace declaration
    – Jesse
    May 28, 2013 at 20:02
  • @Jesse: Of course :).
    – Marcel N.
    May 28, 2013 at 20:02
  • I followed the path of removing it. Yay Syntax and .net variances. I knew it looked right, just for the wrong language. May 28, 2013 at 21:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.