简体   繁体   English

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

[英]EndpointNotFoundException on call to operation of running RESTful WCF service

I have a really strange problem with one of my WCF services. 我的WCF服务之一确实有一个非常奇怪的问题。 I'm pretty sure that most people who have experimented with WCF services have had an EndpointNotFoundException thrown when an endpoint had not been set up correctly in one of their configuration files. 我很确定,当未在其配置文件之一中正确设置端点时,大多数尝试过WCF服务的人都会抛出EndpointNotFoundException From the EndpointNotFoundException class page on MSDN: 从MSDN上的EndpointNotFoundException页面:

The exception that is thrown when a remote endpoint could not be found or reached. 当找不到或到达远程端点时引发的异常。

Further on, it continues: 进一步,它继续:

The endpoint may not be found or reachable because the remote endpoint is down, the remote endpoint is unreachable, or because the remote network is unreachable. 由于远程端点已关闭,远程端点不可访问或由于远程网络不可访问,因此可能找不到或无法访问该端点。

This does not reflect my situation. 不能反映我的情况。 So it seems that receiving an EndpointNotFoundException when working with WCF is not unusual, but this Exception is not thrown when first trying to access the service... instead, it is thrown only when trying to call one of the operations of the service: 因此,似乎在使用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
    ...
}

Interestingly, the Exception message also includes the name of the operation in the mentioned file path: 有趣的是,“ Exception消息还在提到的文件路径中还包括操作的名称:

There was no endpoint listening at http://domain/Folder/ServiceName.svc/OperationName that could accept the message. http://domain/Folder/ServiceName.svc/OperationName上没有侦听终结点的端点可以接受该消息。 This is often caused by an incorrect address or SOAP action. 这通常是由不正确的地址或SOAP操作引起的。 See InnerException, if present, for more details. 有关更多详细信息,请参见InnerException(如果存在)。

The inner Exception has the following message: 内部Exception具有以下消息:

The remote server returned an error: (404) Not Found. 远程服务器返回错误:(404)找不到。

This is particularly confusing for me as I can successfully browse to the service URL and see the default You have created a service page: 这对我来说尤其令人困惑,因为我可以成功浏览到服务URL并查看默认值您已创建服务页面:

在此处输入图片说明

Also, if I navigate to the path in the Exception message, I see an Endpoint not found message on the page: 另外,如果我导航到“ Exception消息中的路径,则会在页面上看到“ 找不到端点”消息:

在此处输入图片说明

However, if I navigate to any operation page of one of my other, working WCF services, I get a standard 400 Bad Request error from the browser, even though the operation works fine. 但是,如果我导航到我的其他一个运行中的WCF服务之一的任何操作页,即使操作正常,我也会从浏览器收到标准的400 Bad Request错误。 So it would seem to me as if this original EndpointNotFoundException could be a red herring... I'm really not sure though, as I've not spent much time working with WCF. 所以在我看来,好像原始的EndpointNotFoundException 可能是个红鲱鱼...不过,我真的不确定,因为我没有花很多时间在WCF上工作。

I'll show my web.config (server side) here just in case anyone needs to see it: 我将在此处显示我的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>

This is the client App.config (bear in mind that this references two WCF services): 这是客户端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>

So if any of the great minds that frequent Stack Overflow could shed some light on this problem for me, I'd greatly appreciate it. 因此,如果任何频繁发生堆栈溢出的好主意可以为我解决这个问题,我将不胜感激。


UPDATE >>> 更新>>>

In response to the first few comments, I suspected that the problem could be caused by an Exception being thrown from the server side code, so I simplified the operation code dramatically... now all it does is this, but I still get the same error: 作为对前几条评论的回应,我怀疑问题可能是由服务器端代码引发Exception引起的,因此我大大简化了操作代码……现在所做的只是这个,但是我仍然得到了相同的结果。错误:

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

Also, I did set up tracing, but it only worked on the client side, so it only told me what I already knew. 另外,我确实设置了跟踪,但是它仅在客户端起作用,因此它只告诉我我已经知道的内容。 I will have a look at the link you provided @BigDaddy, in case it shows how to set up tracing on the server side. 我将看看您提供的@BigDaddy链接,以防它显示了如何在服务器端设置跟踪。

In response to Tewr, I generated the service client using svcutil.exe , but I also tried adding a service reference and letting Visual Studio create the reference for me... both methods resulted in the same error. 作为对Tewr的响应,我使用svcutil.exe生成了服务客户端,但我还尝试添加服务引用并让Visual Studio为我创建引用...这两种方法均导致相同的错误。 Also, I have been updating the service references all day, as I've been making changes. 另外,由于进行更改,我整天都在更新服务引用。 The includeExceptionDetailInFaults="true" setting didn't make any difference, but I'll try adding a dummy operation to the service and try to view it in the browser. includeExceptionDetailInFaults="true"设置没有任何区别,但是我将尝试向该服务添加一个虚拟操作,并尝试在浏览器中查看它。


UPDATE 2 >>> 更新2 >>>

Ok, so I added a simple getter method to the service and updated the references all round like @Tewr suggested. 好的,所以我向服务中添加了一个简单的getter方法,并像@Tewr建议的那样全面更新了引用。 This has just made me more confused... the method: 这让我更加困惑...方法:

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

The implementation just returns a string and I see that value when I access the service in a web browser: 该实现只返回一个string ,当我在Web浏览器中访问该服务时,我会看到该值: 在此处输入图片说明
However, I still get the same error from code, even when calling this same new operation... what does that mean? 但是,即使调用相同的新操作,我仍然会从代码中得到相同的错误……这是什么意思?


UPDATE 3 >>> 更新3 >>>

After taking the advice from the comments, I set up a Service Trace on the service again... I still couldn't get the one working on the server, but on the client, it did output a trace file. 从评论中获取建议后,我在服务上再次设置了服务跟踪...我仍然无法在服务器上运行该服务跟踪,但是在客户端上,它确实输出了跟踪文件。 In that file, I see an InvalidOperationException with the following message: 在该文件中,我看到带有以下消息的InvalidOperationException

Envelope Version 'EnvelopeNone ( http://schemas.microsoft.com/ws/2005/05/envelope/none )' does not support adding Message Headers. 信封版本“ EnvelopeNone( http://schemas.microsoft.com/ws/2005/05/envelope/none )”不支持添加邮件头。

I'm just researching this now, so if you know what this error is about, please let me know. 我现在正在研究此问题,因此,如果您知道此错误的原因,请告诉我。

The problem with WCF is that it is so complex, the Exception s cover so many different errors each and the Exception messages are so vague. WCF的问题在于它是如此的复杂, Exception覆盖了许多不同的错误,并且Exception消息非常模糊。 From my limited experience, it seems like an error message will say one thing, but it will often be wholly, or partly irrelevant to your actual problem. 从我有限的经验来看,错误消息似乎只能说明一件事,但它通常与您的实际问题完全或部分无关。 So I basically kept fixing errors, which unlocked new Exceptions (and I still haven't come to the end of them yet!), but for the purpose of this question, there is an answer. 所以,我基本保持固定错误,解锁新的Exceptions (和我没有来到他们结束呢!),但对这个问题的目的, 一个答案。

So it turned out that the original EndpointNotFoundException was actually thrown because there was an unhandled Exception in the AddExportConfirmation service method implementation. 因此,原来的EndpointNotFoundException 实际上是抛出的,因为AddExportConfirmation服务方法实现中存在未处理的Exception Once I had simplified the code (as in the first question update), that particular Exception went away and was replaced with the next one. 一旦简化了代码(如第一个问题更新中所述),该特定的Exception就消失了,并被下一个替换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM