创建Web引用类时出现NullReferenceException

时间:2013-04-11 12:56:29

标签: c# .net nullreferenceexception web-reference

我有一个引用Web服务的C#/ WPF项目。但是,有时在创建表示它的自动生成类的实例时会得到NullReferenceException

var service = new SSO();

堆栈跟踪如下:

System.NullReferenceException: Object reference not set to an instance of an object.
    in System.Xml.Serialization.XmlSerializer.GetSerializersFromCache(XmlMapping[] mappings, Type type)
    in System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Type type)
    in System.Web.Services.Protocols.SoapClientType..ctor(Type type)
    in System.Web.Services.Protocols.SoapHttpClientProtocol..ctor()
    in MyNamespace.SSO..ctor()

有谁知道这里发生了什么?服务器可能有很短的停机时间,但这不是我希望在网络连接问题时看到的例外情况!

更新:自动生成的类SSO的代码,以防有人发现它相关:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.0.30319.17929")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="SSOSoap", Namespace="http://schemas.example.com/SSO")]
public partial class SSO : System.Web.Services.Protocols.SoapHttpClientProtocol
{
    public SSO()
    {
        this.Url = "http://example.com/SSO.asmx";
        if ((this.IsLocalFileSystemWebService(this.Url) == true))
        {
            this.UseDefaultCredentials = true;
            this.useDefaultCredentialsSetExplicitly = false;
        }
        else
        {
            this.useDefaultCredentialsSetExplicitly = true;
        }
    }

    // a lot of methods here
}

0 个答案:

没有答案