c# – 当操作返回元页面html时,如何更好地诊断WCF服务?
我有一个在IIS7.5(.NET 4)中托管的WCF服务应用程序(wsHttpBinding),我可以在浏览器中导航.svc文件,并且元数据页面成功显示,客户端可以从wsdl生成.
我添加了自己的自定义服务行为来记录未处理的异常(下面的“ErrorHandling”),我正在使用MembershipProvider来获取服务凭据.这是我的完整system.serviceModel配置: <system.serviceModel> <diagnostics wmiProviderEnabled="true"> <messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" maxMessagesToLog="3000" maxSizeOfMessageToLog="-1" /> </diagnostics> <extensions> <behaviorExtensions> <add name="ErrorHandling" type="MyCompany.MyProduct.Services.ErrorHandlerBehavior,MyCompany.MyProduct.Services" /> </behaviorExtensions> </extensions> <services> <service name="MyCompany.MyProduct.Services.ApplicationService" behaviorConfiguration="MyProductServiceBehavior"> <endpoint bindingConfiguration="MyProductWsHttpBinding" binding="wsHttpBinding" contract="MyCompany.MyProduct.Services.IApplicationService" /> </service> <service name="MyCompany.MyProduct.Services.AccountService" behaviorConfiguration="MyProductServiceBehavior"> <endpoint bindingConfiguration="MyProductWsHttpBinding" binding="wsHttpBinding" contract="MyCompany.MyProduct.Services.IAccountService" /> </service> <service name="MyCompany.MyProduct.Services.InvoiceService" behaviorConfiguration="MyProductServiceBehavior"> <endpoint bindingConfiguration="MyProductWsHttpBinding" binding="wsHttpBinding" contract="MyCompany.MyProduct.Services.IInvoiceService" /> </service> <service name="MyCompany.MyProduct.Services.ReportService" behaviorConfiguration="MyProductServiceBehavior"> <endpoint bindingConfiguration="MyProductWsHttpBinding" binding="wsHttpBinding" contract="MyCompany.MyProduct.Services.IReportService" /> </service> <service name="MyCompany.MyProduct.Services.PaymentService" behaviorConfiguration="MyProductServiceBehavior"> <endpoint bindingConfiguration="MyProductWsHttpBinding" binding="wsHttpBinding" contract="MyCompany.MyProduct.Services.IPaymentService" /> </service> </services> <bindings> <wsHttpBinding> <binding name="MyProductWsHttpBinding"> <security mode="Message"> <message clientCredentialType="UserName" establishSecurityContext="true" negotiateServiceCredential="true" /> </security> </binding> </wsHttpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="MyProductServiceBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> <serviceCredentials> <serviceCertificate findValue="MyProductServices" storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName" /> <userNameAuthentication userNamePasswordValidationMode="MembershipProvider" membershipProviderName="AspNetSqlMembershipProvider" /> </serviceCredentials> <ErrorHandling /> <serviceSecurityAudit auditLogLocation="Application" suppressAuditFailure="false" serviceAuthorizationAuditLevel="SuccessOrFailure" messageAuthenticationAuditLevel="SuccessOrFailure" /> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" /> </system.serviceModel> 您可以看到我还启用了安全审核,但事件日志中没有显示任何内容,除了显示消息日志已打开的消息.因此,当客户端调用该操作时,它似乎永远不会进入身份验证阶段. 我也启用了跟踪如下: <system.diagnostics> <sources> <source name="System.ServiceModel" switchValue="All" propagateActivity="true" > <listeners> <add name="xml"/> </listeners> </source> <source name="System.ServiceModel.MessageLogging" switchValue="All"> <listeners> <add name="xml"/> </listeners> </source> <source name="myUserTraceSource" switchValue="Information,ActivityTracing"> <listeners> <add name="xml"/> </listeners> </source> </sources> <sharedListeners> <add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="C:UsersPublicDocumentsservices.svclog" /> </sharedListeners> </system.diagnostics> 当客户端调用主服务中的主操作时,它会收到一条带有以下消息的协议异常: 内容类型text / html; charset =响应消息的UTF-8与绑定的内容类型(application / soap xml; charset = utf-8)不匹配.如果使用自定义编码器,请确保正确实现IsContentTypeSupported方法.响应的前1024个字节是:’#content {FONT-SIZE:0.7em; PADDING-BOTTOM:2em; MARGIN-LEFT:30px} BODY {MARGIN-TOP:0px; MARGIN-LEFT:0px;颜色:#000000; FONT-FAMILY:Verdana;背景颜色:白色} P {MARGIN-TOP:0px; MARGIN-BOTTOM:12px;颜色:#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;背景颜色:#e5e5cc} .heading1 {MARGIN-TOP:0px; PADDING-LEFT:15px; FONT-WEIGHT:正常; FONT-SIZE:26px; MARGIN-BOTTOM:0px; PADDING-BOTTOM:3px; MARGIN-LEFT:-30px;宽度:100%;颜色:#ffffff; PADDING-TOP:10px; FONT-FAMILY:Tahoma; BACKGROUND-COLOR:#003366} .intro {MARGIN-LEFT:-15px} ApplicationService Service’. 当您浏览.svc文件时,您看到的元数据页面的html是什么.因此,似乎服务正在返回该页面作为对操作的响应. 查看services.svclog讲述了同样的故事,实际上日志格式错误是xml,因为这个响应包含在其中而没有标记被转义.跟踪中没有任何有用的信息. 服务器上没有抛出异常,日志什么都没有.这一切都适用于我设置的另一台服务器上的IIS6,只是为了测试它,错误记录也在那里工作. 哪些工具和技术可以帮助我弄清楚根本问题是什么? 更新:这是来自服务器端跟踪的svclog,用于来自新生成的控制台应用客户端的单个请求(擦除以删除个人信息),注意它在最后被截断的方式: 解决方法
检查IIS中的URL重写规则以获取该站点.如果其中一个重定向,则可能导致客户端接收元数据页面作为对操作的响应.我以前见过这种情况,可能会产生误导.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |