Collin
Collin

Reputation: 91

SharePoint 2010 - Using SOAP web service

I've added a reference to a SOAP service in my VS2010 project. I have a form that registers users for a newsletter. For me to get this form to work, I have to edit the SharePoint server's web.config and add in the SOAP bindings. If I don't do that and add it into my project's app.config, the server gives an error:

Could not find default endpoint element that references contract 'contractAPI.Soap' in the ServiceModel client configuration section.

How can I bypass the web.config and use the app.config to configure the SOAP service or set this up programmatically using C#?

Upvotes: 2

Views: 1446

Answers (1)

DavidGouge
DavidGouge

Reputation: 4623

You can set the bindings in your code like this:

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

Upvotes: 2

Related Questions