Thursday, July 4, 2013

Programmatically create endpoints in .NET WCF webservice

Generate Webservice  proxy class generatedProxy.cs
http://stackoverflow.com/questions/8160176/programmatically-create-endpoints-in-net-wcf-service

http://msdn.microsoft.com/en-us/library/aa395212.aspx

I was getting error while trying to use below code for a secure https channel


using System;
using System.ServiceModel;

namespace ConsoleApplication
{
  class Program
  {
    static void Main(string[] args)
    {
      TimeServiceSoapClient client = 
        new TimeServiceSoapClient(
          new BasicHttpBinding(), 
          new EndpointAddress("http://www.nanonull.com/TimeService/TimeService.asmx"));

      Console.WriteLine(client.getCityTime("London"));
    }
  }
}

Error: The provided URI scheme 'https' is invalid; expected 'http'. Parameter name: via

This was fixed after adding below code as explained at http://stackoverflow.com/questions/11563389/custom-binding-the-provided-uri-scheme-https-is-invalid-expected-http-par

var endPoint = new EndpointAddress("https://xxxxx/v2_soap/index/");

var binding = new BasicHttpBinding
{
    Name = "HandlerBinding",
        CloseTimeout = TimeSpan.FromMinutes(1.0),
        HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
        MessageEncoding = WSMessageEncoding.Text,
        MaxReceivedMessageSize = 65536000,
        MaxBufferPoolSize = 65536000,
        UseDefaultWebProxy = true,
        AllowCookies = false,
        BypassProxyOnLocal = false,
        Security =
    {
        Mode =BasicHttpSecurityMode.Transport,
        Transport =
        {
            ClientCredentialType = HttpClientCredentialType.None,
            ProxyCredentialType = HttpProxyCredentialType.None
        },
        Message =
            {
                ClientCredentialType = BasicHttpMessageCredentialType.UserName
            }
    } 
};

Error: The provided URI scheme 'https' is invalid; expected 'http'. Parameter name: via
Error: The provided URI scheme 'https' is invalid; expected 'http'. Parameter name: via

No comments:

c# httpclient The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch

 If we get this error while trying to get http reponse using HttpClient object, it could mean that certificate validation fails for the remo...