我在VS2010项目中添加了对SOAP服务的引用。我有一个表单,用于注册用户的简报。为了让我能够使用此表单,我必须编辑SharePoint服务器的web.config并添加SOAP绑定。如果我不这样做并将其添加到我的项目的app.config中,则服务器会出错:
在ServiceModel客户端配置部分找不到引用合同'contractAPI.Soap'的默认端点元素。
如何绕过web.config并使用app.config配置SOAP服务或使用C#以编程方式设置它?
答案 0 :(得分:2)
您可以在代码中设置绑定,如下所示:
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"));
}