我正在使用自托管的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>