WCF的一个怪异问题,高手请进
来源:互联网 发布:微源码裂变拓客系统 编辑:程序博客网 时间:2024/04/30 16:32
今天遇到一个问题,系统基于WCF框架,不同的服务完全相似的代码,一个就报错,一个成功。而且报错的代码其实际顺利运行完毕所有代码,事务也成功地提交了,只是在返回信息时WCF给了一个错误信息:
<Fault xmlns="http://schemas.microsoft.com/ws/2005/05/envelope/none"><Code><Value>Receiver</Value><Subcode><Value xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</Value></Subcode></Code><Reason><Text xml:lang="zh-CN">message 对象已被释放。</Text></Reason><Detail><ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><HelpLink i:nil="true"/><InnerException i:nil="true"/><Message>message 对象已被释放。</Message><StackTrace> 在 System.ServiceModel.Channels.ByteStreamMessage.InternalByteStreamMessage.get_Properties()↵ 在 System.ServiceModel.OperationContext.get_IncomingMessageProperties()↵ 在 System.ServiceModel.Web.IncomingWebRequestContext.get_UriTemplateMatch()↵ 在 System.ServiceModel.Description.WebHttpBehavior.TrySetupJavascriptCallback(String callbackParameterName)↵ 在 System.ServiceModel.Dispatcher.JavascriptCallbackMessageInspector.BeforeSendReply(Message& reply, Object correlationState)↵ 在 System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.BeforeSendReplyCore(MessageRpc& rpc, Exception& exception, Boolean& thereIsAnUnhandledException)</StackTrace><Type>System.ObjectDisposedException</Type></ExceptionDetail></Detail></Fault>
经过排查,发现是由于Web.Config文件中binging节点的 crossDomainScriptAccessEnabled="true" 属性导致的,去掉后一切正常。微软官方帮助文档说该属性是用来设定是否允许跨域脚本访问,不清楚为何该属性会导致上述问题。只不过我们项目暂时不存在跨域访问问题,故去掉没有大碍。
具体web.config配置文件和代码如下:
<?xml version="1.0" encoding="utf-8"?><configuration> <system.serviceModel> <services> <service behaviorConfiguration="Service.ServiceBehavior" name="VME.Service.PictureService"> <endpoint address="" behaviorConfiguration="VME.Service.ServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="VME.Contract.IPictureService" bindingConfiguration="webBinding" /> </service> <service behaviorConfiguration="Service.ServiceBehavior" name="VME.Service.ServiceService"> <endpoint address="" behaviorConfiguration="VME.Service.ServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="VME.Contract.IServiceService" bindingConfiguration="serviceBinding" /> </service> </services> <behaviors> <endpointBehaviors> <behavior name="VME.Service.ServiceAspNetAjaxBehavior"> <enableWebScript /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="Service.ServiceBehavior"> <serviceThrottling maxConcurrentCalls="50" maxConcurrentSessions="50" maxConcurrentInstances="50"/> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="true" /> <dataContractSerializer maxItemsInObjectGraph="2147483647"/> </behavior> </serviceBehaviors> </behaviors> <protocolMapping> <add binding="webHttpBinding" scheme="http" /> </protocolMapping> <bindings> <webHttpBinding> <binding name="webBinding" useDefaultWebProxy="false" crossDomainScriptAccessEnabled="true" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" sendTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:01:00" closeTimeout="00:01:00" transferMode="Streamed" hostNameComparisonMode="StrongWildcard"> <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" maxDepth="32" maxBytesPerRead="4096" maxNameTableCharCount="16384"/> <security mode="None"></security> </binding> <binding name="serviceBinding" useDefaultWebProxy="false" crossDomainScriptAccessEnabled="true" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" sendTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:01:00" closeTimeout="00:01:00" transferMode="Streamed" hostNameComparisonMode="StrongWildcard"> <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" maxDepth="32" maxBytesPerRead="4096" maxNameTableCharCount="16384"/> <security mode="None"></security> </binding> </webHttpBinding> </bindings> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> </system.serviceModel></configuration>
[ServiceContract]public interface IPictureService{ [OperationContract] [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)] bool SendIdCardPicture(Stream idCardImg);}[ServiceContract]public interface IServiceService{ [OperationContract] [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)] bool AddService(Stream service);}上面IPictureService接口的程序是能正常返回信息,而IServiceService接口的程序就报错。
有高手请给予指点迷津,到底哪里出了问题。
0 0
- WCF的一个怪异问题,高手请进
- 截屏吃内存的问题 高手请进
- 关于结束进程的问题,高手请进。
- 高手请进,小妹请教一个ASP。NET安装问题
- 一个怪异的服务器问题
- 一个怪异的js问题
- 求助,查询问题,高手请进
- [VB.NET]关于EXIF读取的详细问题,高手请进
- 高分求教一个怪异的问题
- 高分求教一个怪异的问题
- 高分求教一个怪异的问题
- 高分求教一个怪异的问题
- 高分求教一个怪异的问题
- 高分求教一个怪异的问题
- 这是一个DirectInput使用出现了一个小问题 directx高手 请进来指点江山
- 高手请进
- 高手请进-----
- 求mina高手帮我解决一个问题(各位mina大侠请进)
- 【极客网】如何成为一名专家级的程序员
- Android开发--RecyclerView使用,看AndroidL新特性
- 【笔记】JavaScript编码规范- 类型分配&强制转换
- 脱壳方法汇总
- 我整理的suse linux 常用命令
- WCF的一个怪异问题,高手请进
- java 基础学习
- unity3d input输入
- Eclipse导入myEclipse项目
- 关于Android 微信APP支付开发中遇到的问题
- 怎样编译Qt下的Oracle驱动
- in与exist , not in与not exist 的区别
- GetMessage和PeekMessage的区别
- ORACLE SQL*Plus® User's Guide and Reference