我有一个MessageInspector类,它实现了IClientMessageInspector。
Sub SaveAsCSVFile
ChDir "C:\Users\paddy\Desktop\NEW CSV files whole CGM date ok!"
ActiveWorkbook.SaveAs Filename:= _
"C:\Users\paddy\Desktop\NEW CSV files whole CGM date ok!\" & _
"3WDL_1 (2014-08-07)10secDataTable sit.csv", _
FileFormat:=xlCSVMac, CreateBackup:=False
End Sub
我在WCF的web.config中配置了这个:
namespace WCFAuthentication
{
public class MessageInspector : IClientMessageInspector
{
public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
//throw new NotImplementedException();
Debug.WriteLine("IClientMessageInspector.AfterReceiveReply called.");
Debug.WriteLine("Message: {0}", reply.ToString());
}
public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
{
//throw new NotImplementedException();
Debug.WriteLine("IClientMessageInspector.BeforeSendRequest called.");
return null;
}
}
}
在运行wcf(在IIS中托管)时,它无法在我们的配置中识别我的“MessageInspector”类。
配置错误
描述:处理为此请求提供服务所需的配置文件时发生错误。请查看下面的具体错误详细信息并相应地修改配置文件。
分析器错误消息:无法加载为扩展名“MessageInspector”注册的类型“WCFAuthentication.MessageInspector,MessageInspector,Version = 0.0.0.0,Culture = neutral,PublicKeyToken = null”。
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<extensions>
<behaviorExtensions>
<add
name="MessageInspector"
type="WCFAuthentication.MessageInspector, MessageInspector, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="restfulBehavior">
<webHttp/>
</behavior>
<behavior name="restfulBehavior_jwt">
<webHttp/>
<MessageInspector/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name ="WCFAuthentication.Service1">
<endpoint address="" behaviorConfiguration="restfulBehavior_jwt" binding="webHttpBinding" contract="WCFAuthentication.IService1"/>
</service>
<service name ="WCFAuthentication.Authentication">
<endpoint address="" behaviorConfiguration="restfulBehavior" binding="webHttpBinding" contract="WCFAuthentication.IAuthentication"/>
</service>
</services>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
答案 0 :(得分:2)
您无法直接添加MessageInspector
,需要实施IEndpointBehavior
和BehaviorExtensionElement
。