我已经通过Visual Studio 2015创建了服务引用。通信工作正常,但我必须从app.config文件中获取应用程序。我试图创建自己的绑定和端点,但实际上我收到SystemNullReference。连接到WebService时的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
在2101.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.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.SecuritySessionClientSettings
1.ClientSecuritySessionChannel.OnOpen(时间跨度 超时)w System.ServiceModel.Channels.CommunicationObject.Open(时间跨度 超时)w System.ServiceModel.Channels.ServiceChannel.OnOpen(时间跨度超时)
W¯¯System.ServiceModel.Channels.CommunicationObject.Open(时间跨度 超时)w System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel。 ICallOnce.Call(ServiceChannel 信道,时间跨度超时)瓦特 System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(时间跨度 超时,CallOnceManager级联)瓦特 System.ServiceModel.Channels.ServiceChannel.EnsureOpened(时间跨度 超时)瓦特System.ServiceModel.Channels。 ServiceChannel.Call(字符串 动作,布尔单向,ProxyOperationRuntime操作,对象[]插件, 对象[]奏,时间跨度超时)瓦特 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage 包括methodCall,ProxyOperationRuntime操作)瓦特 系统.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)异常重新抛出[0]:瓦特 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(即时聊天 reqMsg,即时聊天retMsg)瓦特 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData & MSGDATA,的Int32型)瓦特 WebServices.Testowy.Emailver.EmailVerNoTestEmailSoap.AdvancedVerifyEmail(字符串 电子邮件,的Int32超时,字符串LICENSEKEY)瓦特 WebServices.Test.GetWebService()瓦特 C:\用户\ michal.warchulinski \源\回购\ 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:wiers z 22
对不起很多文字。任何线索可以提供这种豁免?
你把调试器,看看它不喜欢哪个位?你看过哪一行完全抛出异常吗? –
您是否在调用webservice方法之前调用Client.Open()? –
@ChrisWatts调用此方法的代码位于另一个解决方案中。这似乎是异常抛出 “var Client = new Testowy.Emailver.EmailVerNoTestEmailSoapClient(binding,endpoint);”但正如我刚才查看的那样,当项目处于相同的解决方案时,一切正常。 – warkocz