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

C# 调用运行RESTful WCF服务的操作时EndpointNotFoundException,c#,wcf,endpoint,endpointnotfoundexception,C#,Wcf,Endpoint,Endpointnotfoundexception,我的一个WCF服务有一个非常奇怪的问题。我敢肯定,大多数尝试过WCF服务的人在他们的一个配置文件中没有正确设置端点时都会抛出EndpointNotFoundException。从MSDN上的页面: 无法找到或访问远程终结点时引发的异常 此外,它还继续: 由于远程终结点关闭、远程终结点不可访问或远程网络不可访问,因此可能找不到或无法访问终结点 这并不反映我的情况。因此,在使用WCF时接收到EndpointNotFoundException似乎并不罕见,但在首次尝试访问服务时不会引发此异常。。。相反

我的一个WCF服务有一个非常奇怪的问题。我敢肯定,大多数尝试过WCF服务的人在他们的一个配置文件中没有正确设置端点时都会抛出
EndpointNotFoundException
。从MSDN上的页面:

无法找到或访问远程终结点时引发的异常

此外,它还继续:

由于远程终结点关闭、远程终结点不可访问或远程网络不可访问,因此可能找不到或无法访问终结点

这并不反映我的情况。因此,在使用WCF时接收到
EndpointNotFoundException
似乎并不罕见,但在首次尝试访问服务时不会引发此
异常。。。相反,它仅在尝试调用服务的一个操作时抛出:

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
    ...
}
这是客户端
App.config
(请记住,这引用了两个WCF服务):

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

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


更新2>>>

好的,所以我向服务添加了一个简单的getter方法,并更新了所有引用,如@Tewr建议的那样。这让我更加困惑。。。方法:

[XmlSerializerFormat()]
[OperationContract]
[WebGet()]
string GetString();
该实现只返回一个
字符串
,当我在web浏览器中访问该服务时,我会看到该值:
然而,我仍然从代码中得到相同的错误,即使在调用相同的新操作时。。。这是什么意思


更新3>>>

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

信封版本“EnvelopeNone()”不支持添加邮件标题


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

WCF的问题是它太复杂了,
异常
涵盖了太多不同的错误,而
异常
消息太模糊了。从我有限的经验来看,一条错误消息似乎说明了一件事,但它通常与您的实际问题完全或部分无关。因此,我基本上一直在修复错误,从而解锁了新的
异常
(我还没有结束它们!),但对于这个问题,有一个答案


因此,原来的
EndpointNotFoundException
实际上被抛出,因为
AddExportConfirmation
服务方法实现中存在未处理的
异常。一旦我简化了代码(如第一个问题更新中所述),特定的
异常就会消失,并被下一个异常所取代。

如果您还没有这样做,请设置跟踪以查看实际情况。遵循这一点:你的“红鲱鱼”理论是有效的……我以前也遇到过同样的异常,但实际上是服务端的一个未经处理的异常。消费者只是放弃了,并抛出了毯子例外。调试另一端。看起来您正在使用生成的serviceclient。您最近是否更改了服务接口,可能忘记了更新服务引用?另外,我看到您正在使用webHttp绑定,这有助于您仅使用浏览器检查映射。在您的服务上创建一个虚拟函数
[WebGet(UriTemplate=“Ping/”)bool Ping(){return true;}
并尝试从浏览器访问它。。最后一个提示,
includeExceptionDetailInFaults=“true”
可能会对您有所帮助。@您的更新1:启用跟踪应该会对您有所帮助。它帮助了我。它也可以应用于服务器端。尝试更改这些:and initializeData=“D:\Log\Traces.svclog”>将完整路径添加到“initializeData”。当伪函数工作时,服务器上发生错误的可能性较小。对我来说,你的客户端app.config一目了然。在这种情况下,我会启动Fiddler,并将简单、有效的浏览器调用的标题/url与来自.net客户端的标题/url进行比较。当使用.net客户端时,内部异常是404错误,因此.net客户端可能会对操作url执行一些奇怪的操作。
<?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>
public void AddExportConfirmation(string upc, component ingestionFeedback)
{
    WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.OK;
}
[XmlSerializerFormat()]
[OperationContract]
[WebGet()]
string GetString();