我有一个 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)