2009-07-16 37 views
0

我打開[assembly:System.CLSCompliant(true)]內我的C#解決方案的程序集。如何在Web引用中處理符合CLS的內容?

我現在正在爲SharePoint Web Service生成的代碼中收到一些警告。

這裏是一個不符合CLS-的方法之一:

/// <remarks/> 
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://schemas.microsoft.com/sharepoint/soap/GetItem", RequestNamespace="http://schemas.microsoft.com/sharepoint/soap/", ResponseNamespace="http://schemas.microsoft.com/sharepoint/soap/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] 
    public uint GetItem(string Url, out FieldInformation[] Fields, [System.Xml.Serialization.XmlElementAttribute(DataType="base64Binary")] out byte[] Stream) { 
     object[] results = this.Invoke("GetItem", new object[] { 
        Url}); 
     Fields = ((FieldInformation[])(results[1])); 
     Stream = ((byte[])(results[2])); 
     return ((uint)(results[0])); 
    } 

如何刪除這個警告?

謝謝 基思

回答

0

我建議您將您的Web引用放置在未設置爲符合CLS的單獨的類庫項目中。從主代碼中引用該庫。

1

可以標記不符合規定的方法與[CLSCompliant(false)]屬性避免的警告,但似乎擊敗標記您的組件作爲標準的第一場所的對象:想必你希望代碼實際上符合CLS。

爲了使代碼符合要求,您需要從uint/UInt32更改該方法的返回類型。暴露的無符號類型不符合CLS。

您可以改爲返回long/Int64long類型符合CLS標準,將安全地處理任何可能的uint值。

如果你不能或不會編輯生成的代碼(要麼添加屬性要麼改變返回類型),那麼我認爲你唯一的選擇就是將該代碼移動到一個單獨的不兼容的程序集as John suggests

相關問題