0

我有一个引用 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
}
4

0 回答 0