[英]EndpointNotFoundException on call to operation of running RESTful WCF service
我的WCF服务之一确实有一个非常奇怪的问题。 我很确定,当未在其配置文件之一中正确设置端点时,大多数尝试过WCF服务的人都会抛出EndpointNotFoundException
。 从MSDN上的EndpointNotFoundException
类页面:
当找不到或到达远程端点时引发的异常。
进一步,它继续:
由于远程端点已关闭,远程端点不可访问或由于远程网络不可访问,因此可能找不到或无法访问该端点。
这不能反映我的情况。 因此,似乎在使用WCF时收到EndpointNotFoundException
并不罕见,但是在首次尝试访问该服务时不会引发此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)找不到。
这对我来说尤其令人困惑,因为我可以成功浏览到服务URL并查看默认值您已创建服务页面:
另外,如果我导航到“ Exception
消息中的路径,则会在页面上看到“ 找不到端点”消息:
但是,如果我导航到我的其他一个运行中的WCF服务之一的任何操作页,即使操作正常,我也会从浏览器收到标准的400 Bad Request
错误。 所以在我看来,好像原始的EndpointNotFoundException
可能是个红鲱鱼...不过,我真的不确定,因为我没有花很多时间在WCF上工作。
我将在此处显示我的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>
因此,如果任何频繁发生堆栈溢出的好主意可以为我解决这个问题,我将不胜感激。
更新>>>
作为对前几条评论的回应,我怀疑问题可能是由服务器端代码引发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
,当我在Web浏览器中访问该服务时,我会看到该值:
但是,即使调用相同的新操作,我仍然会从代码中得到相同的错误……这是什么意思?
更新3 >>>
从评论中获取建议后,我在服务上再次设置了服务跟踪...我仍然无法在服务器上运行该服务跟踪,但是在客户端上,它确实输出了跟踪文件。 在该文件中,我看到带有以下消息的InvalidOperationException
:
信封版本“ EnvelopeNone( http://schemas.microsoft.com/ws/2005/05/envelope/none )”不支持添加邮件头。
我现在正在研究此问题,因此,如果您知道此错误的原因,请告诉我。
WCF的问题在于它是如此的复杂, Exception
覆盖了许多不同的错误,并且Exception
消息非常模糊。 从我有限的经验来看,错误消息似乎只能说明一件事,但它通常与您的实际问题完全或部分无关。 所以,我基本保持固定错误,解锁新的Exceptions
(和我还没有来到他们结束呢!),但对这个问题的目的, 有一个答案。
因此,原来的EndpointNotFoundException
实际上是抛出的,因为AddExportConfirmation
服务方法实现中存在未处理的Exception
。 一旦简化了代码(如第一个问题更新中所述),该特定的Exception
就消失了,并被下一个替换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.