找不到默认端点元素 .NET 4.0

Posted

技术标签:

【中文标题】找不到默认端点元素 .NET 4.0【英文标题】:Could not find default endpoint element .NET 4.0 【发布时间】:2012-04-25 16:40:33 【问题描述】:

我已将代理添加到 VS2010/.NET 4 解决方案的 Web 服务。我的机器是windows 7操作系统。构建客户端.NET时抛出这个错误:

找不到名为“FulfilmentServicesSoap”的端点元素,并且 合同中的“FulfimentServiceSoap.FulfilmentServicesSoap” ServiceModel 客户端配置部分。这可能是因为没有 为您的应用程序找到了配置文件,或者因为没有 可以在客户端中找到匹配此名称的端点元素 元素。

我在这里找到了一个关于 SO 的类似问题:

Could not find default endpoint element

但是,阅读本文并尝试一些答案对我没有用。我已经多次编辑 app.config 文件,包括:

contract="IFulfimentServiceSoap" name="FulfilmentServicesSoap" />

contract="FulfimentServiceSoap.FulfilmentServicesSoap" name="FulfilmentServicesSoap" />

contract="MYFullNamespace.FulfimentServiceSoap.FulfilmentServicesSoap" name="FulfilmentServicesSoap" />

但是,在每种情况下,当我运行我的 Web 服务时,即使我编辑了配置文件,事件查看器也会显示合同“FulfimentServiceSoap.FulfilmentServicesSoap”。我还必须做些什么来获取 app.config 文件中的更改或有任何其他想法吗?

编辑 - 从 app.config 添加绑定信息

<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="FulfilmentServicesSoap" 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>
        </bindings>
        <client>
            <endpoint address="http://localhost/WLR3.Web.services/FulfilmentServices.asmx"
                binding="basicHttpBinding" bindingConfiguration="FulfilmentServicesSoap"
               contract="FulfimentServiceSoap.FulfilmentServicesSoap"name="FulfilmentServicesSoap" />
        </client>
    </system.serviceModel>

EDIT - 创建客户端的代码。

FulfimentServiceSoap.FulfilmentServicesSoap fulfilmentServices = new FulfimentServiceSoap.FulfilmentServicesSoapClient("FulfilmentServicesSoap");

【问题讨论】:

没有发布更多信息(配置),很难提供帮助。 你的app.config、web.config...需要绑定配置。 编辑了问题以在 app.config 中包含绑定配置 - 我可以在 IE 中点击 localhost 上的 asmx 页面 好的,包括你如何创建你的客户端的代码。 添加的代码是创建客户端。 【参考方案1】:

如果您部署的项目不使用 web.config 或 app.config(例如 Sharepoint Feature),您的代码块无法读取 web 或应用配置,可能会出现以下异常。

您可以在调用 Web 服务之前使用以下代码块来操作 Web 或应用配置条目。

BasicHttpBinding httpBinding = new BasicHttpBinding();
httpBinding.Name = "DMS_WSSoap";
httpBinding.CloseTimeout = new TimeSpan(0, 1, 0);
httpBinding.OpenTimeout = new TimeSpan(0, 1, 0);
httpBinding.ReceiveTimeout = new TimeSpan(0, 10, 0);
httpBinding.SendTimeout = new TimeSpan(0, 1, 0);
httpBinding.AllowCookies = false;
httpBinding.BypassProxyOnLocal = false;
httpBinding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
httpBinding.MaxBufferSize = 65536;
httpBinding.MaxBufferPoolSize = 524288;
httpBinding.MaxReceivedMessageSize = 65536;
httpBinding.MessageEncoding = WSMessageEncoding.Text;
httpBinding.TextEncoding = Encoding.UTF8;
httpBinding.TransferMode = TransferMode.Buffered;
httpBinding.UseDefaultWebProxy = true;

httpBinding.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas();
httpBinding.ReaderQuotas.MaxDepth = 32;
httpBinding.ReaderQuotas.MaxStringContentLength = 8192;
httpBinding.ReaderQuotas.MaxArrayLength = 16384;
httpBinding.ReaderQuotas.MaxBytesPerRead =  4096;
httpBinding.ReaderQuotas.MaxNameTableCharCount =16384;

httpBinding.Security.Mode = BasicHttpSecurityMode.None;
httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
httpBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
httpBinding.Security.Transport.Realm = "";
httpBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

//The url of web services.
EndpointAddress endpoint = new EndpointAddress("http://localhost/_layouts/DMS_WS/DMS_WS.asmx");

//one of the example web service which has been referenced in visual studio IDE.
LibraryWatcherWebService.DMS_WSSoapClient lservice = new LibraryWatcherWebService.DMS_WSSoapClient( httpBinding, endpoint);

【讨论】:

【参考方案2】:

好吧,无论如何我都想通了 - 会在这里发布,以防它帮助其他人。创建的 DLL 我复制到了我的 Application/Libraries 文件夹中。 (我没有复制创建的 app.config 文件)。在创建客户端的代码中,我编写了绑定和端点地址详细信息,然后将它们传递给 SoapClient 构造函数。所以我的代码如下所示:

BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress remoteAddress = new EndpointAddress("http://localhost/WLR3.Web.services/FulfilmentServices.asmx");
binding.Name = "FulfilmentServicesSoap";
binding.AllowCookies = false;

FulfimentServiceSoap.FulfilmentServicesSoap fulfilmentServices = new FulfimentServiceSoap.FulfilmentServicesSoapClient(binding, remoteAddress);

【讨论】:

以上是关于找不到默认端点元素 .NET 4.0的主要内容,如果未能解决你的问题,请参考以下文章

找不到引用合同的默认端点元素 - 托管 wcf

找不到引用合同的默认端点元素:通过 Powershell cmdlet 连接到 WCF 端点

WCF 错误 - 找不到引用合同“UserService.UserService”的默认端点元素

WCF 找不到默认端点

找不到端点异常 - WCF Web 服务

找不到端点异常 - WCF Web 服务