C# 连接到WebService时的SystemNullReference
我已经通过Visual Studio 2015创建了一个服务引用。通信工作正常,但我必须获得应用程序免费的app.config文件。我试图创建自己的绑定和端点,但实际上我收到了SystemNullReference 我的代码示例:C# 连接到WebService时的SystemNullReference,c#,webservice-client,C#,Webservice Client,我已经通过Visual Studio 2015创建了一个服务引用。通信工作正常,但我必须获得应用程序免费的app.config文件。我试图创建自己的绑定和端点,但实际上我收到了SystemNullReference 我的代码示例: var binding = CreateBinding(); var endpoint = new EndpointAddress("http://ws.cdyne.com/emailverify/Emailvernotestemail.asmx");
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.IssuanceTokenProviderBase1.Donegationation(时间跨度
超时)w
System.ServiceModel.Security.SspiNegotiationTokenProvider.OnOpen(TimeSpan
超时)w
System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan
超时)w
System.ServiceModel.Channel.CommunicationObject.Open(时间跨度
超时)w
System.ServiceModel.Security.CommunicationObjectSecurityTokenProvider.Open(TimeSpan
超时)w
System.ServiceModel.Security.SymmetricSecurity协议.OnOpen(TimeSpan
超时)w
System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan
超时)w
System.ServiceModel.Channel.CommunicationObject.Open(时间跨度
超时)w
System.ServiceModel.Channel.SecurityChannel工厂
1.ClientSecurityChannel1.OnOpen(时间跨度
超时)w
System.ServiceModel.Channel.CommunicationObject.Open(时间跨度
超时)w
System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.DoOperation(SecuritySessionOperation
操作,端点地址目标,Uri通过,SecurityToken
currentToken,TimeSpan超时)w
System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.GetTokenCore(TimeSpan
超时)w
System.IdentityModel.Selectors.SecurityTokenProvider.GetToken(TimeSpan
超时)w
System.ServiceModel.Security.SecuritySessionClient设置
1.ClientSecuritySessionChannel.OnOpen(TimeSpan
超时)w
System.ServiceModel.Channel.CommunicationObject.Open(时间跨度
超时)w
System.ServiceModel.Channel.ServiceChannel.OnOpen(TimeSpan超时)w System.ServiceModel.Channel.CommunicationObject.Open(时间跨度 超时)w System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.iAllonce.Call(ServiceChannel 通道,时间间隔超时)w System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan 超时,CallonManager级联)w System.ServiceModel.Channels.ServiceChannel.com重新打开(TimeSpan 超时)w System.ServiceModel.Channels.ServiceChannel.Call(字符串 操作,布尔单向,ProxyOperationRuntime操作,对象[]ins, 对象[]输出,时间跨度超时)w System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage 方法调用,ProxyOperationRuntime操作)w System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage (信息) 在[0]处重试异常:w System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)w System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData,Int32型)w WebServices.Testowy.Emailver.EmailVerNoTestEmailSoap.AdvancedVerifyEmail(字符串 电子邮件,Int32超时,字符串LicenseKey)w Test.GetWebService()w C:\Users\michal.warchulinski\Source\Repos\Aplixcom\u CommonComponents\Aplixcom\u 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
对不起,我发了很多短信。有什么线索可以提供这种解释吗 在调用webservice方法之前,尝试在客户端上调用
Open
方法。有时它有助于解决一些对象初始化问题
根据堆栈跟踪,我们可以看到,当您调用webservice方法时,它实际上尝试了打开客户机。但很明显,它试图以不同于Open
方法的方式打开频道
不幸的是,我没有知识来解释为什么开放电话有时需要,有时不需要
如果有人能解释一下,我会很高兴的。你有没有打开调试器,看看它不喜欢哪一位?你看到哪一行抛出了异常了吗?你是在调用webservice方法之前调用Client.Open()吗?@ChrisWatts调用此方法的代码在另一个解决方案中。“var Client=new Testowy.Emailver.EmailVerNoTestEmailSoapClient(binding,endpoint);”中似乎出现了异常,但正如我刚才检查的那样,当项目位于同一个解决方案中时,一切正常。@Mt.Schneiders不,我错过了它,这正是需要的。它现在起作用了,但你能解释为什么有时需要,有时不需要吗?