Temp权限引起的WCF问题

时间:2022-04-23
本文章向大家介绍Temp权限引起的WCF问题,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

WCF按照BasicHttpBinding方式发布,部署到服务器上,再在其他项目中引用的时候,就会出现不能正确下载元数据的错误。使用svcutil.exe工具进行测试,出现下面的问题。在Log跟踪中看到:

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent%22> 
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system%22> 
<EventID>131075</EventID> 
<Type>3</Type> 
<SubType Name="Error">0</SubType> 
<Level>2</Level> 
<TimeCreated SystemTime="2009-09-10T08:28:29.0217396Z" /> 
<Source Name="System.ServiceModel" /> 
<Correlation ActivityID="{00000000-0000-0000-0f00-0060010000fb}" /> 
<Execution ProcessName="w3wp" ProcessID="5628" ThreadID="5" /> 
<Channel /> 
<Computer>OA-HRPAYOPR</Computer> 
</System> 
<ApplicationData> 
<TraceData> 
<DataItem> 
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord%22 Severity="Error"> 
<TraceIdentifier>http://msdn.microsoft.com/zh-CN/library/System.ServiceModel.Diagnostics.ThrowingException.aspx</TraceIdentifier> 
<Description>Throwing an exception.</Description> 
<AppDomain>/LM/W3SVC/1688268109/Root-1-128970447760280025</AppDomain> 
<Exception> 
<ExceptionType>System.ServiceModel.ProtocolException, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType> 
<Message>Content Type application/soap+xml; charset=utf-8 was sent to a service expecting text/xml; charset=utf-8.  The client and service bindings may be mismatched.</Message> 
<StackTrace> 
at System.ServiceModel.Channels.HttpInput.ThrowHttpProtocolException(String message, HttpStatusCode statusCode, String statusDescription) 
at System.ServiceModel.Channels.HttpInput.ValidateContentType() 
at System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(Exception&amp; requestException) 
at System.ServiceModel.Channels.HttpRequestContext.CreateMessage() 
at System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext context, ItemDequeuedCallback callback) 
at System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult result) 
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest() 
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest() 
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object state) 
at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.WorkItem.Invoke2() 
at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.WorkItem.Invoke() 
at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.ProcessCallbacks() 
at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.CompletionCallback(Object state) 
at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped) 
at System.ServiceModel.Diagnostics.Utility.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped) 
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP) 
</StackTrace> 
<ExceptionString>System.ServiceModel.ProtocolException: Content Type application/soap+xml; charset=utf-8 was sent to a service expecting text/xml; charset=utf-8.  The client and service bindings may be mismatched.</ExceptionString> 
<DataItems> 
<Data> 
<Key>System.ServiceModel.Channels.HttpInput.HttpStatusCode</Key> 
<Value>UnsupportedMediaType</Value> 
</Data> 
<Data> 
<Key>System.ServiceModel.Channels.HttpInput.HttpStatusDescription</Key> 
<Value>Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'.</Value> 
</Data> 
</DataItems> 
</Exception> 
</TraceRecord> 
</DataItem> 
</TraceData> 
</ApplicationData> 
</E2ETraceEvent>
Content Type application/soap+xml; charset=utf-8 was sent to a service expecting text/xml; charset=utf-8.  The client and service bindings may be mismatched 
  Cannot process the message because the content type ‘application/soap+xml; charset=utf-8′ was not the expected type ‘text/xml; charset=utf-8′. 

查了好久,得到A few tips when using WCF with BizTalk Server 2006 R2的启示,估计可能是C:WINDOWSTEMP没有写权限。将其设为everyone可读写后,则完全正常了。