【发布时间】:2014-03-10 16:16:04
【问题描述】:
我的一项 WCF 服务有一个非常奇怪的问题。我很确定大多数尝试过 WCF 服务的人在他们的某个配置文件中未正确设置端点时都会抛出EndpointNotFoundException。来自 MSDN 上的EndpointNotFoundException class 页面:
无法找到或到达远程端点时引发的异常。
接下来,它继续:
可能因为远程端点关闭、远程端点不可达或远程网络不可达而找不到或无法访问端点。
这确实不反映了我的情况。因此,似乎在使用 WCF 时收到 EndpointNotFoundException 并不少见,但是当 first 尝试访问该服务时,not 会抛出这个 Exception... 而不是,仅在尝试调用服务的其中一项操作时才抛出:
using (ExportConfirmationServiceClient client = new ExportConfirmationServiceClient(
"WebHttpBinding_IExportConfirmationService")) // <-- Exception is NOT thrown here
{
...
component releaseConfirmation = DeserializeTestXmlFile(filePath);
client.AddExportConfirmation("5051275066302", releaseConfirmation);
// Exception is thrown on call to service operation on line above
...
}
有趣的是,Exception 消息中还包含上述文件路径中的操作名称:
http://domain/Folder/ServiceName.svc/OperationName上没有可以接受消息的端点侦听。这通常是由不正确的地址或 SOAP 操作引起的。有关详细信息,请参阅 InnerException(如果存在)。
内部Exception有如下信息:
远程服务器返回错误:(404) Not Found.
这让我特别困惑,因为我可以成功浏览到服务 URL 并看到默认的您已创建服务页面:
另外,如果我导航到 Exception 消息中的路径,我会在页面上看到 Endpoint not found 消息:
但是,如果我导航到我的其他工作 WCF 服务之一的任何操作页面,我会从浏览器收到标准的 400 Bad Request 错误,即使该操作工作正常。所以在我看来,这个原始的EndpointNotFoundException 可能是一条红鲱鱼......不过我真的不确定,因为我没有花太多时间与 WCF 合作。 p>
我将在此处显示我的 web.config(服务器端)以防万一有人需要查看它:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="Midas.WebConfirmations.ExportConfirmationServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttp">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
<services>
<service name="Midas.WebConfirmations.ExportConfirmationService" behaviorConfiguration="Midas.WebConfirmations.ExportConfirmationServiceBehaviour">
<endpoint address="" binding="webHttpBinding" contract="Midas.WebConfirmations.IExportConfirmationService" behaviorConfiguration="webHttp" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
这是客户端 App.config(请记住,这引用了两个 WCF 服务):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IDataService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="WebHttpBinding_IExportConfirmationService" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000"/>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="Midas.WebConfirmations.ExportConfirmationServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webEndpointBehavior">
<webHttp defaultBodyStyle="Wrapped" defaultOutgoingResponseFormat="Xml" helpEnabled="true"/>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://devbucket.ministryofsound.mos.local/MidasWebServices/DataService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDataService" contract="Midas.WebServiceClients.IDataService" name="BasicHttpBinding_IDataService" />
<endpoint address="http://devbucket.ministryofsound.mos.local/MidasWebConfirmations/ExportConfirmationService.svc" binding="webHttpBinding" bindingConfiguration="WebHttpBinding_IExportConfirmationService" behaviorConfiguration="webEndpointBehavior" contract="IExportConfirmationService" name="WebHttpBinding_IExportConfirmationService" />
</client>
</system.serviceModel>
</configuration>
因此,如果有哪位经常使用 Stack Overflow 的伟人能为我阐明这个问题,我将不胜感激。
更新>>>
针对前几个cmets,我怀疑问题可能是由服务器端代码抛出Exception引起的,所以我大大简化了操作代码......现在它所做的就是这样,但是我仍然得到同样的错误:
public void AddExportConfirmation(string upc, component ingestionFeedback)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.OK;
}
另外,我确实设置了跟踪,但它只在客户端起作用,所以它只告诉我我已经知道的。我会看看你提供的链接@BigDaddy,以防它显示如何在服务器端设置跟踪。
为了响应 Tewr,我使用 svcutil.exe 生成了服务客户端,但我也尝试添加服务引用并让 Visual Studio 为我创建引用...这两种方法都导致了相同的错误。此外,我整天都在更新服务引用,因为我一直在进行更改。 includeExceptionDetailInFaults="true" 设置没有任何区别,但我会尝试在服务中添加一个虚拟操作并尝试在浏览器中查看。
更新 2 >>>
好的,所以我向服务添加了一个简单的 getter 方法,并像@Tewr 建议的那样全面更新了引用。这只是让我更加困惑......方法:
[XmlSerializerFormat()]
[OperationContract]
[WebGet()]
string GetString();
该实现只返回一个string,当我在网络浏览器中访问该服务时,我看到了该值:
但是,我仍然从代码中得到相同的错误,即使调用这个 same 新操作...这是什么意思?
更新 3 >>>
在听取了cmets的建议后,我再次在服务上设置了一个Service Trace……我仍然无法让那个在服务器上工作,但是在客户端上,它确实输出了一个跟踪文件。在该文件中,我看到一个 InvalidOperationException 并带有以下消息:
信封版本“EnvelopeNone (http://schemas.microsoft.com/ws/2005/05/envelope/none)”不支持添加邮件标头。
我现在只是在研究这个,所以如果你知道这个错误是关于什么的,请告诉我。
【问题讨论】:
-
如果您还没有这样做,请设置跟踪以查看实际情况。关注这个:stackoverflow.com/questions/14217700/…
-
你的红鲱鱼理论是有效的......我以前也遇到过同样的异常,但现实是服务端的一个未处理的异常。消费者只是放弃并抛出了毯子异常。调试另一端。
-
看起来您正在使用生成的服务客户端。您最近是否更改了服务接口,并且可能忘记更新服务引用?另外,我看到您使用 webHttp 绑定,这有助于您仅使用浏览器检查映射。在您的服务
[WebGet(UriTemplate = "Ping/")] bool Ping() { return true; }上创建一个虚拟函数并尝试从浏览器访问它。最后一个提示,includeExceptionDetailInFaults="true"可能会对您有所帮助。 -
@Your UPDATE 1:启用跟踪应该对您有所帮助。它帮助了我。它也可以应用于服务器端。尝试更改这些:
和 initializeData= "D:\Log\Traces.svclog"> 添加完整路径到“initializeData”。 -
当你的虚拟函数工作时,错误不太可能出现在服务器上。您的客户端 app.config 对我来说一目了然。在这种情况下,我会启动 Fiddler 并将简单、有效的浏览器调用的 headers/url 与来自 .net 客户端的调用进行比较。由于您的内部异常是使用 .net 客户端时出现 404 错误,因此您的 .net 客户端可能对操作 url 做了一些奇怪的事情。
标签: c# wcf endpoint endpointnotfoundexception