0

我正在使用自托管的 WCF 服务,并且我的服务出现了一些奇怪的行为:我使用 IDispatchMessageInspector 的实现来跟踪我的服务处理的请求/响应。

当我使用“添加服务引用对话框”添加我的服务时,一切正常。AfterReceivedRequest 和 BeforeSendReply 被触发。

当我使用代码创建绑定/端点时,只有服务可以正常工作,但 AfterReceivedRequest 和 BeforeSendReply 不会被触发。

如果有人能指出我正确的方向,我会很高兴。

马可。

编辑:这是客户端创建的代码:

Public Shared Function Do_RM(ByVal RMParameter As roClsRMParameter) As ROD.RM.Services.RoClsRMResult

    Dim StartAdresse As String
    Dim myBinding As BasicHttpBinding
    Dim oRes As ROD.RM.Services.RoClsRMResult = Nothing

    myBinding = Create_Binding()
    myBinding.OpenTimeout = New TimeSpan(0, 0, TimeOutInSekunden)
    myBinding.SendTimeout = New TimeSpan(0, 0, TimeOutInSekunden)
    StartAdresse = "http://MyServer:8731/BASIC"
    Dim Address = New EndpointAddress(StartAdresse)

    Dim Client = New ROD.RM.Services.RODIS_QS_RMClient(myBinding, Address)
    Client.Endpoint.Contract = Create_ContractDescription()

    Client.Open()
    oRes = Client.DoRM(RMParameter.A_BEL,
                       RMParameter.A_POS,
                       RMParameter.AVO,
                       RMParameter.Qualitaet,
                       RMParameter.Fehlernummer,
                       RMParameter.Anlage,
                       RMParameter.ChargenNr,
                       RMParameter.EinzelRueckmeldung,
                       RMParameter.NurTest,
                       RMParameter.Standort)
    Client.Close()
    Return oRes
End Function

Private Shared Function Create_ContractDescription() As ContractDescription

    Dim oContract As ContractDescription
    oContract = ContractDescription.GetContract(GetType(ROD.RM.Services.IRODIS_QS_RM), GetType(ROD.RM.Services.RODIS_QS_RMClient))
    Return oContract
End Function

Private Shared Function Create_Binding() As BasicHttpBinding

    Dim oHttpBinding As BasicHttpBinding = New BasicHttpBinding()

    oHttpBinding.Name = "BasicHttpBinding_IRODIS_QS_RM"
    oHttpBinding.CloseTimeout = TimeSpan.FromMinutes(1)
    oHttpBinding.OpenTimeout = TimeSpan.FromMinutes(1)
    oHttpBinding.ReceiveTimeout = TimeSpan.FromMinutes(10)
    oHttpBinding.SendTimeout = TimeSpan.FromMinutes(1)
    oHttpBinding.BypassProxyOnLocal = False
    oHttpBinding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard
    oHttpBinding.MaxBufferPoolSize = 524288
    oHttpBinding.MaxReceivedMessageSize = 65536
    oHttpBinding.MessageEncoding = WSMessageEncoding.Text
    oHttpBinding.TextEncoding = Encoding.UTF8
    oHttpBinding.UseDefaultWebProxy = True
    oHttpBinding.AllowCookies = False

    oHttpBinding.ReaderQuotas.MaxDepth = 32
    oHttpBinding.ReaderQuotas.MaxArrayLength = 16384
    oHttpBinding.ReaderQuotas.MaxStringContentLength = 8192
    oHttpBinding.ReaderQuotas.MaxBytesPerRead = 4096
    oHttpBinding.ReaderQuotas.MaxNameTableCharCount = 16384

    Return oHttpBinding
End Function

以下是服务检查员的部分:

Imports System.ServiceModel.Description

Public Class roClsRMLogBehavior
    Implements IEndpointBehavior

    Public Sub ApplyDispatchBehavior(ByVal endpoint As _
               System.ServiceModel.Description.ServiceEndpoint, ByVal _
               endpointDispatcher As _
               System.ServiceModel.Dispatcher.EndpointDispatcher) _
        Implements System.ServiceModel.Description.IEndpointBehavior.ApplyDispatchBehavior

        Dim oInspector As roClsRMLog
        oInspector = New roClsRMLog
        endpointDispatcher.DispatchRuntime.MessageInspectors.Add(oInspector)
End Sub

结束类

在 app.Config 中:

<extensions>
  <behaviorExtensions>
    <add name="roClsRMLogBehavior" type="RODIS_QS_BUCHEN_SERVICE.roclsRMLogBehaviorExtensionElement, RODIS_QS_BUCHEN_SERVICE, Version=1.1.3.1,Culture=neutral,PublicKeyToken=null"/>
  </behaviorExtensions>  
</extensions>
4

0 回答 0