我正在尝试使用已配置的端点在 IIS(IIS7、Windows 7)上设置 WCF 服务,并且与 IIS 配置一样,这是一个充满伤害的世界。该服务在 VS2010 的调试器下工作正常,但是当我开始部署它时,我在打开时收到以下消息http://localhost:9000/MyApplication/_vti_bin/ListData.svc
:
[UriFormatException: Invalid URI: The hostname could not be parsed.]
System.Runtime.AsyncResult.End(IAsyncResult result) +650220
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +210733
System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +166
有趣的是,如果我刷新它,消息会发生变化:
[ArgumentException: An item with the same key has already been added.]
System.Runtime.AsyncResult.End(IAsyncResult result) +650220
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +210733
System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +166
我认为第二个错误是第一个错误的结果,所以我试图先找到它。
现在,我知道您在想什么:“在这个关头看到一个又长又无聊的 Web.Config 文件真是太好了。” 你的愿望就是我的命令:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="loggingenabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true"/>
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="SecurityBehavior" name="MSMQSecuredService.SecuredMSMQService">
<endpoint address="net.msmq://MyMachine/private/securedqueue"
binding="netMsmqBinding" bindingConfiguration="SecuredBinding"
name="EndpointMSMQ" contract="MSMQSecuredService.ISecuredMSMQService">
<identity>
<dns value="MyMachine" />
</identity>
</endpoint>
<!-- I have tried configuring the endpoint address to everything from the full path to this "/" with no change in outcome -->
<endpoint address="/" binding="basicHttpBinding" name="EndPointHTTP"
contract="MSMQSecuredService.ISecuredMSMQService" />
<endpoint address="mex" binding="mexHttpBinding" name="EndPointIMEX"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://MyMachine:9000/MyApplication" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="SecurityBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
<serviceCredentials>
<serviceCertificate findValue="CertServer" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
<clientCertificate>
<certificate findValue="CertClient" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
<authentication certificateValidationMode="None"/>
</clientCertificate>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netMsmqBinding>
<binding name="SecuredBinding" exactlyOnce="false" receiveErrorHandling="Fault">
<security mode="Message">
<message clientCredentialType="Certificate"/>
</security>
</binding>
</netMsmqBinding>
</bindings>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
显然,我已经努力混淆确切的机器、应用程序和端口名称,所以如果那里有轻微的不匹配,可能不是问题。
在 IIS 上,我已将站点上的绑定配置为包含 net.msmq - 我对该问题的最佳猜测是“绑定信息”不正确 - 如果我将其设置为当前机器的机器名称,我会收到上述消息,如果我将它设置为“localhost”,它给了我一个 ASP.Net 服务器错误,事件日志和 WCF 跟踪文件中出现以下内容:
The service '/MyApplication/_vti_bin/ListData.svc' does not exist. ---> System.ServiceModel.EndpointNotFoundException: The service '/MyApplication/_vti_bin/ListData.svc' does not exist.
我猜它抱怨的 URI 可能是绑定信息中的主机名,但我找不到任何关于它需要什么的信息,或者如果localhost
正确,如何深入研究问题。
编辑添加:启用 WCF 跟踪后,我看到发生以下模式:
<Description>MsmqActivation service started scan for queues.</Description>
<AppDomain>/LM/W3SVC/2/ROOT/MyApplication-1-130053972428149879</AppDomain>
然后
<Description>Throwing an exception.</Description><AppDomain>/LM/W3SVC/2/ROOT/My-Application-1-130053972428149879</AppDomain>
<Exception>
<ExceptionType>System.ServiceModel.EndpointNotFoundException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>The service '/MyApplication/_vti_bin/ListData.svc' does not exist.</Message><StackTrace> at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity)
at System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath, EventTraceActivity eventTraceActivity)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object state)
at System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
</StackTrace><ExceptionString>System.ServiceModel.EndpointNotFoundException: The service '/MyApplication/_vti_bin/ListData.svc' does not exist.</ExceptionString>
</Exception>
最后我们看到这个:
<Description>MsmqActivation service cannot discover queues.</Description>
<AppDomain>/LM/W3SVC/2/ROOT/MyApplication-1-130053250352242318</AppDomain>
<ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/DictionaryTraceRecord">
<Host>.</Host>
<PublicQueues>True</PublicQueues>
</ExtendedData>
<Exception>
<ExceptionType>System.Messaging.MessageQueueException, System.Messaging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</ExceptionType>
<Message>A workgroup installation computer does not support the operation.</Message>
<StackTrace>
at System.Messaging.MessageQueue.GetMachineId(String machineName)
at System.Messaging.MessageQueueCriteria.set_MachineName(String value)
at System.Messaging.MessageQueue.GetPublicQueuesByMachine(String machineName)
at System.ServiceModel.Channels.MsmqBindingMonitor.OnTimer(Object state)
</StackTrace>
<ExceptionString>System.Messaging.MessageQueueException (0x80004005): A workgroup installation computer does not support the operation.
at System.Messaging.MessageQueue.GetMachineId(String machineName)
at System.Messaging.MessageQueueCriteria.set_MachineName(String value)
at System.Messaging.MessageQueue.GetPublicQueuesByMachine(String machineName)
at System.ServiceModel.Channels.MsmqBindingMonitor.OnTimer(Object state)
</ExceptionString>
</Exception>
现在这个最后的异常看起来可能是最具指示性的——当我试图写入的队列是时,系统似乎正在寻找一个公共./private$/MyApplication
队列——那么我需要改变什么以将其指向正确的方向?