【发布时间】:2012-10-12 03:51:59
【问题描述】:
我有一个 Web 解决方案,其中有一个 WCF 服务项目。我们需要支持“无cookie”。所以在web.config中,它被设置为
<sessionState
mode="SQLServer"
sqlConnectionString="Data Source=ds;Initial Catalog=db;User Id=uid;Password=pwd"
allowCustomSqlDatabase="true"
cookieless="true"
timeout="720"
regenerateExpiredSessionId="false"/>
WCF 服务将支持会话,因此我们还在 web.config 中将“aspNetCompatibilityEnabled”设置为 true。
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true"/>
服务和接口如下,
[ServiceContract(SessionMode=SessionMode.Allowed)]
public interface ICDOCService
{ }
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class CDOCService : ICDOCService
{ }
我们面临的问题是我们无法从任何客户端应用程序访问服务。 (网络应用、WCF 测试客户端)
当我们通过 WCF 测试客户端访问它时,显示以下错误,
调用服务失败。可能原因:服务离线或无法访问;客户端配置与代理不匹配;现有代理无效。有关更多详细信息,请参阅堆栈跟踪。您可以尝试通过启动新代理、恢复到默认配置或刷新服务来恢复。
内容类型
text/html;响应消息的charset=UTF-8与绑定的内容类型不匹配(multipart/related; type="application/xop+xml")。如果使用自定义编码器,请确保正确实现IsContentTypeSupported方法。响应的前 1024 个字节是:
<HTML>
<HEAD>
<link rel="alternate" type="text/xml" href="http://localhost:53721/Services/CDOCService.svc?disco"/>
<STYLE type="text/css">#content{ FONT-SIZE: 0.7em; PADDING-BOTTOM: 2em;
MARGIN-LEFT: 30px}BODY{MARGIN-TOP: 0px; MARGIN-LEFT: 0px; COLOR: #000000;
FONT-FAMILY: Verdana; BACKGROUND-COLOR: white}P{MARGIN-TOP: 0px; MARGIN-BOTTOM:
12px;
COLOR: #000000; FONT-FAMILY: Verdana}PRE{BORDER-RIGHT: #f0f0e0 1px solid;
PADDING-RIGHT: 5px; BORDER-TOP: #f0f0e0 1px solid; MARGIN-TOP: -5px;
PADDING-LEFT: 5px; FONT-SIZE: 1.2em; PADDING-BOTTOM: 5px; BORDER-LEFT: #f0f0e0
1px solid; PADDING-TOP: 5px; BORDER-BOTTOM: #f0f0e0 1px solid; FONT-FAMILY:
Courier New; BACKGROUND-COLOR: #e5e5cc}.heading1{MARGIN-TOP: 0px; PADDING-LEFT:
15px; FONT-WEIGHT: normal; FONT-SIZE: 26px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM:
3px; MARGIN-LEFT: -30px; WIDTH: 100%; COLOR: #ffffff; PADDING-TOP: 10px;
FONT-FAMILY: Tahoma; BACKGROUND-COLOR: #003366}.intro{MARGIN-LEFT: -15px}
</STYLE>
<TITLE>CDOCService Service</TITLE></HEAD><BODY><DIV id="content"><P '.
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at ICDOCService.GetCDOCCount(String institutionID, String mrnID, String userID, String callingSystemID, String securityToken)
at CDOCServiceClient.GetCDOCCount(String institutionID, String mrnID, String userID, String callingSystemID, String securityToken)
【问题讨论】:
-
当您没有 cookie 时,URL 会被修改,并且会在其中放入会话 ID。我想知道这是否导致了问题?
-
感谢您的回复。当我们将 "either" cookieless 设置为 "false" 或 "aspNetCompatibilityEnabled" 设置为 "false" 时,服务 "can" 被调用。但是这两个都是需要的,因为我们需要从服务中访问会话值,并且我们需要支持 cookieless。
-
你说的是真的。由于 url 正在更改,因此无法调用服务,但还需要这 2 个设置:(
-
听起来您有相互排斥的要求。如果您绝对不能使用 cookie,是否有另一种方法可以在不使用 Session 的情况下访问所需的信息?也许是持久数据存储(如数据库中的表)?
-
感谢蒂姆的建议。是的,我们最终选择删除“aspNetCompatibilityEnabled”并使用不同的存储或将相关信息作为参数传递给服务。感谢您的宝贵时间!
标签: wcf