C#.NET WebService WSDL错误CS0030:无法转换类型' string' to' ArrayOfString'

时间:2016-02-04 09:35:03

标签: c# web-services wcf wsdl invalidoperationexception

我有一个包含字符串数组的WSDL。定义如下:

<xsd:complexType name="ArrayOfString">
    <xsd:sequence>
        <xsd:element name="string" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
</xsd:complexType>

可以在此处下载并检查完整的WSDL:GS1 EPCGlobal 1.0.1 WSDL

使用Visual Studio 2013 Tools for C#的 svcutil 生成数据协定后,它生成了一个类,如下所示:

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.33440")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "urn:epcglobal:epcis-query:xsd:1")]
[System.Xml.Serialization.XmlRootAttribute("GetQueryNamesResult", Namespace = "urn:epcglobal:epcis-query:xsd:1", IsNullable = false)]
public partial class ArrayOfString
{

  private string[] stringField;

  /// <remarks/>
  [System.Xml.Serialization.XmlElementAttribute("string", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
  public string[] @string
  {
    get
    {
      return this.stringField;
    }
    set
    {
      this.stringField = value;
    }
  }
}

现在,当我尝试在代理上调用任何操作时:

var poll = new Poll
{
  queryName = "SimpleEventQuery",
  @params = new[]
  {
    new QueryParam {name = "MyParam1", value = "123"},
    new QueryParam {name = "MyParam2", value = "Test"},
  }
};

try
{
  var proxy = new EPCISServiceClient("TEST", "http://thisisthehost:12345/poll");
  proxy.ClientCredentials.UserName.UserName = "XXXX";
  proxy.ClientCredentials.UserName.Password = "AAAA";

  var result = proxy.poll(poll);

  Console.WriteLine(result.queryName);
}
catch (Exception ex)
{
  Console.WriteLine(ex);
}

我总是得到一个InvalidOperationException:

Unable to generate a temporary class (result=1).
error CS0030: Cannot convert type 'string' to 'ArrayOfString'
error CS0029: Cannot implicitly convert type 'ArrayOfString' to 'string'

任何想法如何&#34;强迫&#34; svcutil使用string []而不是生成一个单独的类或任何其他可能来修复它?

0 个答案:

没有答案