2010-07-27 50 views
1

我有一个Web服务,它有一个参数类型为Collection(Byte)的方法。 当我尝试使用wsdl命令生成代理,但数据类型被转换为字节的单维数组。无法生成具有类型泛型集合数据类型的方法的wsdl文件。

所以我想创建wsdl文件,将类型作为集合(字节)使用添加为服务引用,但即使我指定集合类型为Collection.objectModel仍参数具有数据类型作为单维数组的字节。

有没有办法做到这一点,或手动我需要改变代理文件。

回答

0

你需要指定集合类型:

SvcUtil工具/吨:代码 /ct:System.Collections.Generic.List`1

Full SvcUtil documentation here

+0

我曾尝试使用高级选项中的添加服务引用 ,但仍在wdsl中,数据类型表示为 tns:ArrayOfBase64Binary所以创建代理时,它会创建为字节数组而不是集合(字节) – kurozakura 2010-07-27 05:39:11

+0

WSDL将始终显示ArrayOfWhatever,因为泛型类型不是可以用XSD和WSDL。当您从WSDL生成代码时,您可以选择是否生成数组,列表等。 – jrista 2010-07-27 15:18:05

+0

在web服务的情况下看起来像它的设计。 – kurozakura 2010-07-30 06:28:16

0

我也创建了一个Web服务,其中一个方法返回字节的集合数组。 我附上示例代码及其生成的wsdl。希望这可以帮助你

public byte[][] GetPDFs(String searchQuery) 
    { 
List<Byte[]> list = new List<byte[]>(); 
// DO YOUR WORK 
return list.ToArray(); 
} 
在WSDL

和genetated wsdl:type

<wsdl:types> 
    <s:schema elementFormDefault="qualified" targetNamespace="http://TDS.elixir.com/"> 
     <s:element name="GetPDFs"> 
     <s:complexType> 
      <s:sequence> 
      <s:element minOccurs="0" maxOccurs="1" name="searchQuery" type="s:string" /> 
      </s:sequence> 
     </s:complexType> 

     </s:element> 
     <s:element name="GetPDFsResponse"> 
     <s:complexType> 
      <s:sequence> 
      <s:element minOccurs="0" maxOccurs="1" name="GetPDFsResult" type="tns:ArrayOfBase64Binary" /> 
      </s:sequence> 
     </s:complexType> 
     </s:element> 
     <s:complexType name="ArrayOfBase64Binary"> 

     <s:sequence> 
      <s:element minOccurs="0" maxOccurs="unbounded" name="base64Binary" nillable="true" type="s:base64Binary" /> 
     </s:sequence> 
     </s:complexType> 
    </s:schema> 
    </wsdl:types> 

和生成的代理代码(Wsdl.exe用或使用添加引用)是这样的:

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GetPDFs", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] 
    public byte[][] GetPDFs(string searchQuery) { 
     object[] results = this.Invoke("GetPDFs", new object[] { 
        searchQuery}); 
     return ((byte[][])(results[0])); 
    } 

请让我知道你是否需要进一步的帮助。