2013-12-13 69 views
0

我有一個Web服務,它使用我們擁有的DLL中的特定類型。因此,例如我們在Visual Studio中的Web服務解決方案是這樣的:從Web服務公開DLL的類型

Solution 
    ACMEWebService (proj) 
    Utils (proj) 

然後我在我的ACMEWebService其中預計存在於Util類某一類型WebMethod。它看起來是這樣的:

[WebMethod] 
public void SomeWebMethod (int Id, CustomDateClass date) 
{ 
    // my code here 
} 

所以CustomDateClass是位於Utils項目的類。 Utils項目只是構建到一個DLL文件。


我的客戶端應用程序引用了Web服務。它所做的是它產生所謂的代理類,看起來像這樣:

[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.1432")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://acme/Services")] 
public partial class CustomDateClass { 
    private short yearField; 
    private byte monthField; 

    public short Year { 
     get { 
      return this.yearField; 
     } 
     set { 
      this.yearField = value; 
     } 
    } 

    public byte Month { 
     get { 
      return this.monthField; 
     } 
     set { 
      this.monthField = value; 
     } 
    } 
} 

[System.Web.Services.Protocols.SoapHeaderAttribute("CustomSoapHeaderValue")] 
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://acme/Services/SomeMethod" ...)] 
public void SomeMethod(int id, CustomDateClass date) { 
    object[] results = this.Invoke("SomeMethod", new object[] { 
       id, 
       date}); 
} 

在這種代理類我也看到了CustomDateClass類和Web方法SomeWebMethod(int Id, CustomDateClass date)

問題不過是,是從代理類此方法不期望從Utils DLL一個CustomDateClass對象,但代理類的命名空間......

有沒有辦法迫使網絡從Utils DLL公開該類型的服務?

然後,我可以簡單地引用我的CLient應用程序中的Utils.dll,並將實例中的實例從Utils DLL傳遞迴Web服務,而不是現在代理類中引用的類。

回答

1

在代理類生成器(也稱爲Web服務引用嚮導)中,有一個複選框可用來重用現有類型。引用你的dll並且啓用這個複選框來更新web服務引用。

0

您可以將您的Util DLL的引用添加到具有代理類的項目。然後,您可以更改方法簽名以接受來自Util DLL的對象。如果你的Util DLL裏面的類名和圖類似於Web服務所期望的,那麼它應該不成問題。