Web サービスの URL からポートを削除しようとしています。Web サービスは、複数のサーバー間で負荷分散されます。次のコードは、Production for C# で正しく動作しています。ただし、この特定のプロジェクトでは、VB を使用する必要があります。私はそれを変換し、コンパイル エラーは発生していませんが、次の実行時エラーが発生しています。
プロパティ '
type
' の値を解析できません。WebServicesSoapPortRemovalReflector
エラー:アセンブリ ' ' から型 ' ' を読み込めませんでしWebService1
た。
私が読んだものはすべて、常にこの記事を参照しています: http://blogs.msdn.com/b/kaevans/archive/2005/11/16/493496.aspx
C# (これは動作します。エラーはありません。)
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 (実行時エラーを受け取る)
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 (C# と VB の両方で同じ)
<webServices>
<soapExtensionReflectorTypes>
<add type="WebService1.WebServicesSoapPortRemovalReflector, WebService1" />
</soapExtensionReflectorTypes>
</webServices>