调用运行RESTful WCF服务的操作时的EndpointNotFoundException

时间:2014-03-10 16:16:04

标签: c# wcf endpoint endpointnotfoundexception

我的一个WCF服务有一个非常奇怪的问题。我很确定大多数尝试过WCF服务的人在其配置文件中没有正确设置端点时会抛出EndpointNotFoundException。来自MSDN上的EndpointNotFoundException class页:

  

无法找到或到达远程端点时引发的异常。

接下来,它继续:

  

由于远程端点已关闭,远程端点无法访问或远程网络无法访问,因此可能无法找到或无法访问端点。

反映了我的情况。因此,在使用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)Not Found。

这对我来说尤其令人困惑,因为我可以成功浏览到服务网址并查看默认您已创建服务页面:

enter image description here

此外,如果我导航到Exception消息中的路径,我会在页面上看到 Endpoint not found 消息:

enter image description here

但是,如果我导航到我的其他工作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>

因此,如果任何经常出现Stack Overflow的伟大思想能够为我解释这个问题,我会非常感激。


更新&gt;&gt;&gt;

在回复前几条评论时,我怀疑问题可能是由服务器端代码抛出Exception引起的,所以我大大简化了操作代码...现在它只是这样做了,但我仍然得到同样的错误:

public void AddExportConfirmation(string upc, component ingestionFeedback)
{
    WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.OK;
}

另外,我做了设置跟踪,但它只在客户端工作,所以它只告诉我我已经知道的。我将查看您提供的@BigDaddy链接,以防它显示如何在服务器端设置跟踪。

为了回应Tewr,我使用svcutil.exe生成了服务客户端,但我也尝试添加服务引用并让Visual Studio为我创建引用...两种方法都导致了相同的错误。此外,我一直在更新服务引用,因为我一直在进行更改。 includeExceptionDetailInFaults="true"设置没有任何区别,但我会尝试向服务添加虚拟操作,并尝试在浏览器中查看它。


更新2&gt;&gt;&gt;

好的,所以我在服务中添加了一个简单的getter方法,并像@Tewr建议的那样全面更新了引用。这让我更加困惑......方法:

[XmlSerializerFormat()]
[OperationContract]
[WebGet()]
string GetString();

实现只返回string,当我在Web浏览器中访问服务时,我看到了该值: enter image description here
但是,我仍然从代码中获得相同的错误,即使在调用此相同的新操作时......这意味着什么?


更新3&gt;&gt;&gt;

在收到评论的建议后,我再次在服务上设置服务跟踪...我仍然无法让服务器上的服务器工作,但在客户端上,它确实输出了一个跟踪文件。在该文件中,我看到InvalidOperationException,其中包含以下消息:

  

信封版本'EnvelopeNone(http://schemas.microsoft.com/ws/2005/05/envelope/none)'不支持添加邮件标题。

我现在正在研究这个,所以如果你知道这个错误是什么,请告诉我。

1 个答案:

答案 0 :(得分:2)

WCF的问题在于它非常复杂,Exception涵盖了很多不同的错误,Exception消息是如此模糊。从我有限的经验来看,似乎错误信息会说一件事,但它通常会与您的实际问题完全或部分无关。所以我基本上一直在修复错误,解锁了新的Exceptions(我仍然还没有结束它们!),但是出于这个问题的目的,那里有答案。

事实证明原始的EndpointNotFoundException实际上是 ,因为Exception服务方法实现中存在未处理的AddExportConfirmation。一旦我简化了代码(如第一个问题更新),那个特定的Exception就会消失,并被替换为下一个。

相关问题