问题描述
|
我有一个带有basicHttp绑定的简单WCF服务。该服务在IIS7中本地托管(Win7便携式计算机)。我可以在以下位置浏览服务:http://localhost/musicstore/musicstore.svc
(端口80)
我已经开发了一个简单的Windows窗体客户端应用程序来调用该服务。它工作正常,但我真的很想通过Fiddler2查看消息的调用/响应。当我浏览Web时,Fiddler2会很高兴地报告流量,因此我无法理解为什么它没有接听此WCF呼叫?
还有另一种方法可以查看WCF调用中的数据。也许有Microsoft工具?
客户端配置为:
<?xml version=\"1.0\" encoding=\"utf-8\" ?>
<configuration>
<system.serviceModel>
<client>
<endpoint address=\"http://localhost/musicstore/musicstore.svc\"
binding=\"basicHttpBinding\" bindingConfiguration=\"\" contract=\"MusicStore.IMusicStore\"
name=\"BasicHttp\" />
</client>
</system.serviceModel>
</configuration>
服务配置为:
<services>
<service behaviorConfiguration=\"MusicStoreBehavior\" name=\"MusicStore\">
<endpoint address=\"\" binding=\"basicHttpBinding\" contract=\"IMusicStore\">
<identity>
<dns value=\"localhost\" />
</identity>
</endpoint>
<endpoint address=\"mex\" binding=\"mexHttpBinding\" contract=\"IMetadataExchange\" />
</service>
</services>
解决方法
查看WCF正在做什么的最简单方法是打开WCF自己的登录。您可以通过编辑web.config并添加
<system.diagnostics>
<sources>
<source name=\"System.ServiceModel.MessageLogging\">
<listeners>
<add name=\"messages\"
type=\"System.Diagnostics.XmlWriterTraceListener\"
initializeData=\"c:\\logs\\messages.svclog\" />
</listeners>
</source>
</sources>
</system.diagnostics>
<system.serviceModel>
<diagnostics>
<messageLogging
logEntireMessage=\"true\"
logMalformedMessages=\"false\"
logMessagesAtServiceLevel=\"true\"
logMessagesAtTransportLevel=\"false\"
maxMessagesToLog=\"3000\"
maxSizeOfMessageToLog=\"2000\"/>
</diagnostics>
</system.serviceModel>
MSDN提供了有关您可以配置的内容的更多详细信息。您可以在服务跟踪查看器中查看日志。
,这个问题有很多重复,其中许多都有正确答案。您应该使用http://localhost.fiddler/作为目标,.NET将正确代理请求。然后,Fiddler会将\“ localhost.fiddler \”更改为\“ localhost \”,然后再传递请求。
,您可以修改客户端的配置文件:
<configuration>
<system.net>
<defaultProxy>
<proxy bypassonlocal=\"false\" usesystemdefault=\"true\" />
</defaultProxy>
</system.net>
</configuration>
或者您可以使用:
GlobalProxySelection.Select = new WebProxy(\"127.0.0.1\",8888);
来自:Fiddler网站
,我遇到了同样的问题,并通过以下方式解决了问题:
在IIS Express中托管您的服务
使用Documents / IISExpress / config中的IISExpress的applicationhost.config将绑定添加到您的外部LAN ip
使用荷兰语nico的代理配置(请参见下文)
确保您的客户端应用程序使用您的\'external \'IP。因此是192.168.1.X而不是localhost。
您可能需要更改WCF配置,以允许对asp.net 4.0进行多个绑定
<serviceHostingEnvironment multiplesitebindingsenabled=\"true\"/>