Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从web服务公开DLL的类型_C#_Web Services_Proxy_Proxy Classes - Fatal编程技术网

C# 从web服务公开DLL的类型

C# 从web服务公开DLL的类型,c#,web-services,proxy,proxy-classes,C#,Web Services,Proxy,Proxy Classes,我有一个Web服务,它使用我们拥有的DLL中的特定类型。例如,我们在Visual Studio中的Web服务解决方案如下所示: Solution ACMEWebService (proj) Utils (proj) [WebMethod] public void SomeWebMethod (int Id, CustomDateClass date) { // my code here } [System.CodeDom.Compiler.GeneratedCodeAttri

我有一个Web服务,它使用我们拥有的DLL中的特定类型。例如,我们在Visual Studio中的Web服务解决方案如下所示:

Solution
  ACMEWebService (proj)
  Utils (proj)
[WebMethod]
public void SomeWebMethod (int Id, CustomDateClass date)
{
    // my code here
}
[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});
}
然后在我的
ACMEWebService
中有
WebMethod
,它期望
Util
类中存在某种类型。它看起来像这样:

Solution
  ACMEWebService (proj)
  Utils (proj)
[WebMethod]
public void SomeWebMethod (int Id, CustomDateClass date)
{
    // my code here
}
[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
是一个位于
Utils
项目中的类。该
Utils
项目只是构建到一个DLL文件中


我的客户端应用程序引用Web服务。它所做的是生成一个所谓的代理类,如下所示:

Solution
  ACMEWebService (proj)
  Utils (proj)
[WebMethod]
public void SomeWebMethod (int Id, CustomDateClass date)
{
    // my code here
}
[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
对象,而是从代理类命名空间中得到

有没有办法强制Web服务从Utils DLL公开类型


然后我可以简单地从我的客户端应用程序中引用Utils.dll,并将作为Utils dll实例的对象传递回Web服务,而不是像现在这样在代理类中引用的类。

您可以将Util dll的引用添加到具有代理类的项目中。然后,您可以更改方法签名以接受来自Util dll的对象。如果Util dll中的类名和图表与web服务期望的类名和图表类似,则这应该不是问题。

在代理类生成器(也称为web服务引用向导)中,有一个复选框,可以在可能的情况下重用现有类型。引用dll并在启用此复选框的情况下更新web服务引用