【问题标题】:SharePoint 2010 - Using SOAP web serviceSharePoint 2010 - 使用 SOAP Web 服务
【发布时间】:2012-02-22 15:05:37
【问题描述】:

我在我的 VS2010 项目中添加了对 SOAP 服务的引用。我有一个表格,可以为用户注册时事通讯。为了让这个表单工作,我必须编辑 SharePoint 服务器的 web.config 并添加 SOAP 绑定。如果我不这样做并将其添加到我的项目的 app.config 中,服务器会给出错误:

在 ServiceModel 客户端配置部分中找不到引用合约“contractAPI.Soap”的默认端点元素。

如何绕过 web.config 并使用 app.config 配置 SOAP 服务或使用 C# 以编程方式进行设置?

【问题讨论】:

    标签: c# asp.net sharepoint sharepoint-2010 web-parts


    【解决方案1】:

    您可以像这样在代码中设置绑定:

    internal static WServiceSoapClient CreateWebServiceInstance()
    {
        BasicHttpBinding binding = new BasicHttpBinding();
        binding.SendTimeout = TimeSpan.FromMinutes(1);
        binding.OpenTimeout = TimeSpan.FromMinutes(1);
        binding.CloseTimeout = TimeSpan.FromMinutes(1);
        binding.ReceiveTimeout = TimeSpan.FromMinutes(10);
        binding.AllowCookies = false;
        binding.BypassProxyOnLocal = false;
        binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
        binding.MessageEncoding = WSMessageEncoding.Text;
        binding.TextEncoding = System.Text.Encoding.UTF8;
        binding.TransferMode = TransferMode.Buffered;
        binding.UseDefaultWebProxy = true;
        return new WServiceSoapClient(binding, new EndpointAddress("http://yourservice.com/service.asmx"));
    }
    

    【讨论】:

    • 我之前尝试过该解决方案,但仍然遇到相同的错误。即使手动定义了这些值,WebPart 仍会查看 web.config。
    • 在我使用 Web 服务的代码中,我使用: WServiceSoapClient client = WebServiceHelper.CreateWebServiceInstance() 而不是 new WServiceSoapClient() 并且配置文件根本没有受到影响,因为所有它需要的信息已在绑定中提供。你能发布一些你的代码吗?
    • 我添加了工作 SOAP 配置值以及您发布的内容。 'binding.Name = "SoapBinding"; binding.ReaderQuotas.MaxDepth = 32; binding.ReaderQuotas.MaxStringContentLength = 8192; binding.ReaderQuotas.MaxArrayLength = 16384; binding.ReaderQuotas.MaxBytesPerRead = 4096; binding.ReaderQuotas.MaxNameTableCharCount = 16384;绑定.MaxBufferSize = 65536;绑定.MaxBufferPoolSize = 524288;绑定.MaxReceivedMessageSize = 65536; client.ClientCredentials.UserName.UserName = "用户名"; client.ClientCredentials.UserName.Password = "密码";'
    猜你喜欢
    • 2012-04-14
    • 1970-01-01
    • 1970-01-01
    • 2011-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    相关资源
    最近更新 更多