我的一项 WCF 服务有一个非常奇怪的问题。我很确定大多数尝试过 WCF 服务的人EndpointNotFoundException
在他们的配置文件中没有正确设置端点时都会遇到问题。从 MSDN 上的EndpointNotFoundException
课程页面:
无法找到或到达远程端点时引发的异常。
进一步,它继续:
由于远程端点已关闭、远程端点不可达或远程网络不可达,端点可能无法找到或无法访问。
这并不反映我的情况。因此,似乎EndpointNotFoundException
在使用 WCF 时收到一个并不少见,但在第一次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 并看到默认的You have created a service页面:
此外,如果我导航到Exception
消息中的路径,我会在页面上看到Endpoint not found消息:
但是,如果我导航到我的其他工作 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 的伟人能为我阐明这个问题,我将不胜感激。
更新>>>
针对前几条评论,我怀疑问题可能是由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();
实现只返回 a string
,当我在 Web 浏览器中访问该服务时,我看到了该值:
但是,即使在调用相同的新操作时,我仍然从代码中得到相同的错误......这是什么意思?
更新 3 >>>
在听取了评论的建议后,我再次在服务上设置了一个服务跟踪......我仍然无法让那个在服务器上工作,但在客户端上,它确实输出了一个跟踪文件。在该文件中,我看到一个InvalidOperationException
带有以下消息的:
信封版本“EnvelopeNone ( http://schemas.microsoft.com/ws/2005/05/envelope/none )”不支持添加邮件标头。
我现在只是在研究这个,所以如果你知道这个错误是关于什么的,请告诉我。