1

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

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

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

找不到默认端点元素

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

合同="IFulfimentServiceSoap" 名称="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");
4

2 回答 2

2

如果您部署的项目不使用 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);
于 2012-10-23T09:11:07.320 回答
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);
于 2012-04-13T13:26:28.353 回答