我有一个在IIS7.5(.NET 4)中托管的WCF服务应用程序(wsHttpBinding),我可以浏览浏览器中的.svc文件,并且成功显示元数据页面,客户端可以从wsdl生成。如何在操作返回元页面html时更好地诊断WCF服务?
我已经添加了自己的自定义服务行为来记录未处理的异常(下面的“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:\Users\Public\Documents\services.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;字体大小:1.2em; PADDING-BOTTOM:5px; BORDER-LEFT:#f0f0e0 1px solid; PADDING-TOP:5px; BORDER-BOTTOM:#f0f0e0 1px solid; FONT-FAMILY:快递新品;背景颜色:#e5e5cc} .heading1 {MARGIN-TOP:0px; PADDING-LEFT:15px;字体重量:正常;字体大小:26px; MARGIN-BOTTOM:0px; PADDING-BOTTOM:3px; MARGIN-LEFT:-30px; WIDTH:100%; COLOR:#ffffff; PADDING-TOP:10px; FONT-FAMILY:Tahoma;背景颜色:#003366} .intro {MARGIN-LEFT:-15px} ApplicationService Service'。
这是您浏览到.svc文件时看到的元数据页面的html。因此,看起来服务正在返回该页面作为对操作的响应。
查看services.svclog告诉同样的故事,实际上日志格式错误xml,因为这个响应被包含在它里面,没有标签被转义。跟踪中没有任何有用的信息。
服务器上没有任何异常,日志没有任何内容。这一切都适用于我设置的另一台服务器上的IIS6,以便对其进行测试,并且错误日志记录也可以在此处运行。
什么工具和技巧可以帮助我弄清根本问题是什么?
UPDATE:这里是从用于从一个新生成的控制台应用程序的客户端(洗涤,以除去个人信息)的单个请求进行服务器端跟踪的svclog,注意它是如何在端截短: http://pastebin.com/mksL0FFY
尝试查看服务器上的事件日志。它应该在应用程序文件夹中有失败的消息。 – LarsTech
事件日志中没有任何内容,唯一的条目是消息日志记录已打开:消息日志记录已打开。敏感信息可能会以明文形式记录下来,即使它是在网上加密的:例如,邮件正文。 进程名称:w3wp 进程ID:6604 – WheatControm
您是否已将svclog加载到ServiceTraceViewer工具中?与阅读原始XML相比,您可以更轻松地阅读它。 – Tim