0

I have created a service reference by Visual Studio 2015. Communication works fine but I have to get application free of app.config file. I tried to create own binding and endpoint but in effect I receive SystemNullReference.

Sample of my code:

    var binding = CreateBinding();
    var endpoint = new EndpointAddress("http://ws.cdyne.com/emailverify/Emailvernotestemail.asmx");
    var Client = new Testowy.Emailver.EmailVerNoTestEmailSoapClient(binding, endpoint );

private static BasicHttpBinding CreateBinding()
        {
            var binding = new BasicHttpBinding();
            binding.Name = "EmailVerNoTestEmailSoap";
            binding.CloseTimeout = TimeSpan.FromMinutes(1);
            binding.OpenTimeout = TimeSpan.FromMinutes(1);
            binding.ReceiveTimeout = TimeSpan.FromMinutes(10);
            binding.SendTimeout = TimeSpan.FromMinutes(1);
            binding.AllowCookies = false;
            binding.BypassProxyOnLocal = false;
            binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
            binding.MaxBufferSize = 65536;
            binding.MaxBufferPoolSize = 524288;
            binding.MessageEncoding = WSMessageEncoding.Text;
            binding.TextEncoding = System.Text.Encoding.UTF8;
            binding.TransferMode = TransferMode.Buffered;
            binding.UseDefaultWebProxy = true;

            binding.ReaderQuotas.MaxDepth = 32;
            binding.ReaderQuotas.MaxStringContentLength = 8192;
            binding.ReaderQuotas.MaxArrayLength = 16384;
            binding.ReaderQuotas.MaxBytesPerRead = 4096;
            binding.ReaderQuotas.MaxNameTableCharCount = 16384;

            binding.Security.Mode = BasicHttpSecurityMode.None;
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
            binding.Security.Transport.Realm = "";
            binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
            binding.Security.Message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default;
            return binding;
        }

System.NullReferenceException: Object reference not set to an instance of an object.

Server stack trace: w System.ServiceModel.Security.IssuanceTokenProviderBase1.DoNegotiation(TimeSpan timeout) w System.ServiceModel.Security.SspiNegotiationTokenProvider.OnOpen(TimeSpan timeout) w System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout) w System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) w System.ServiceModel.Security.CommunicationObjectSecurityTokenProvider.Open(TimeSpan timeout) w System.ServiceModel.Security.SymmetricSecurityProtocol.OnOpen(TimeSpan timeout) w System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout) w System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) w System.ServiceModel.Channels.SecurityChannelFactory1.ClientSecurityChannel1.OnOpen(TimeSpan timeout) w System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) w System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.DoOperation(SecuritySessionOperation operation, EndpointAddress target, Uri via, SecurityToken currentToken, TimeSpan timeout) w System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.GetTokenCore(TimeSpan timeout) w System.IdentityModel.Selectors.SecurityTokenProvider.GetToken(TimeSpan timeout) w System.ServiceModel.Security.SecuritySessionClientSettings1.ClientSecuritySessionChannel.OnOpen(TimeSpan timeout) w System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) w System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
w System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) w System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout) w System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade) w System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout) w System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) w System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) w System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: w System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) w System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) w WebServices.Testowy.Emailver.EmailVerNoTestEmailSoap.AdvancedVerifyEmail(String email, Int32 timeout, String LicenseKey) w WebServices.Test.GetWebService() w C:\Users\michal.warchulinski\Source\Repos\Aplixcom_CommonComponents\Aplixcom_CommonComponents\WebServices\ClientClasses.cs:wiersz 65 w App.Main() w C:\Users\michal.warchulinski\Documents\Visual Studio 2015\Projects\Soap\Soap\Program.cs:wiersz 22

Excuse me a lot of text. Any clues what can provide this exeption?

MykeDev
  • 5
  • 3
  • Have you put the debugger on and seen which bit it doesnt like? Have you seen which line exactly throws the exception? – Chris Watts Mar 29 '17 at 17:20
  • Are you calling Client.Open() before invoking the webservice method? – Mt. Schneiders Mar 29 '17 at 17:34
  • @ChrisWatts The code that call this method is in another solution. It seems that exception is throw in "var Client = new Testowy.Emailver.EmailVerNoTestEmailSoapClient(binding, endpoint );" But as I have checked moment ago when project is in the same solution everything works fine. – MykeDev Mar 29 '17 at 17:40
  • @Mt.Schneiders No, I missed it and it is exactly what was needed. It works now but can you explain why it is sometimes needed and sometimes is not? – MykeDev Mar 29 '17 at 17:54

1 Answers1

0

Try calling the Open method on the client before invoking the webservice method. Sometimes it helps solving some object initialization issues.

We can see based on your stack trace, that it actually tried opening the client when you invoked the webservice method. But apparently it tried opening the channel in a different way compared to the Open method.

Unfortunately, I don't have the knowledge to explain why the Open call is sometimes needed and sometimes not.

I'ld be glad if someone could explain that as well.

Mt. Schneiders
  • 4,568
  • 3
  • 17
  • 40