我已经通过Visual Studio 2015创建了一个服务引用。通信工作正常,但我必须让应用程序免于app.config文件。我试图创建自己的绑定和端点,但实际上我收到了SystemNullReference。
我的代码示例:
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:未将对象引用设置为实例 一个对象。
服务器堆栈跟踪:w System.ServiceModel.Security.IssuanceTokenProviderBase
1.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.SecurityChannelFactory
{1.ClientSecurityChannel {1}} 1.ClientSecuritySessionChannel.OnOpen(时间跨度 超时)w System.ServiceModel.Channels.CommunicationObject.Open(时间跨度 超时)w System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
w System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan 超时)w System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel 频道,TimeSpan超时)w System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(时间跨度 超时,CallOnceManager级联)w System.ServiceModel.Channels.ServiceChannel.EnsureOpened(时间跨度 超时)w System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime操作,Object [] ins, 对象[]出局,TimeSpan超时)w System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime operation)w System.ServiceModel.Channels.ServiceChannelProxy.Invoke(即时聊天 消息)在[0]处重新抛出异常:w System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(即时聊天 reqMsg,IMessage retMsg)w System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&安培; msgData,Int32类型)w WebServices.Testowy.Emailver.EmailVerNoTestEmailSoap.AdvancedVerifyEmail(字符串 电子邮件,Int32超时,字符串LicenseKey)w WebServices.Test.GetWebService()w C:\ Users \用户michal.warchulinski \源\回购\ Aplixcom_CommonComponents \ Aplixcom_CommonComponents \ Web服务\ ClientClasses.cs:wiersz 65 w App.Main()w C:\ Users \ michal.warchulinski \ Documents \ Visual Studio 2015 \ Projects \ Soap \ Soap \ Program.cs:wiersz 22
请原谅我很多文字。什么能提供这个例外的线索?
答案 0 :(得分:0)
在调用webservice方法之前,尝试在客户端上调用Open
方法。有时它有助于解决一些对象初始化问题。
我们可以根据您的堆栈跟踪看到,它实际上在您调用webservice方法时尝试打开客户端。但显然,与Open
方法相比,它尝试以不同的方式打开频道。
不幸的是,我没有足够的知识解释为什么有时需要公开电话,有时不需要。
如果有人能够解释这一点,我会很高兴。