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

标签 .net wcf wcf-binding endpoint

我已将代理添加到 VS2010/.NET 4solution 的 Web 服务。我的机器是windows 7操作系统。构造客户端 .NET 时抛出此错误:

Could not find endpoint element with name 'FulfilmentServicesSoap' and contract 'FulfimentServiceSoap.FulfilmentServicesSoap' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.

我在这里找到了一个类似类型的问题:

Could not find default endpoint element

然而,通读本文并尝试一些答案对我来说并没有效果。我已经多次编辑了 app.config 文件,包括:

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

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

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

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

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

<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>

编辑 - 创建客户端的代码。

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

最佳答案

如果您部署的项目不使用 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);

关于.net - 找不到默认端点元素.NET 4.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10138750/

相关文章:

c# - Entity Framework 6 找不到 <model>.<entity> 的 CLR 类型

c# - 在一个对象中初始化一个集合?

.net - LINQ : Generics with IQueryable

c# - WCF:使用 URL 中的参数调用服务 &

wcf - 为什么 WCF 在使用安全性时会导致 channel 出错?

.net - 反 spy 软件删除的单点登录 cookie

c# - ServiceController.Start() 未达到 "Running"状态

c# - 添加对 WCF 服务的引用的最佳实践

c# - 使用 ServiceHost 类及其构造函数了解 WCF 自托管方法

wcf - 如何更改 WCf 服务的 wsdl 文件中的默认架构位置?