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

时间:2012-04-13 09:55:54

标签: .net wcf wcf-binding endpoint

我已经将代理添加到VS2010 / .NET 4solution的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>

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

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

2 个答案:

答案 0 :(得分:2)

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

在调用Web服务之前,您可以使用以下代码块来操作Web或app config条目。

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

答案 1 :(得分:1)

好的,所以无论如何都想到了这一点 - 将在这里发布以防万一它可以帮助其他人。创建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);
相关问题