连接到Salesforce问题C#

时间:2017-03-24 13:43:56

标签: c# salesforce

我收到以下错误,似乎无法找出原因。

System.Xml.dll中出现未处理的“System.InvalidOperationException”类型异常

其他信息:无法生成临时类(结果= 1)。

错误CS0030:无法将类型'iDdataPrep.SFDC.ListViewRecordColumn []'转换为'iDdataPrep.SFDC.ListViewRecordColumn'

错误CS0030:无法将类型'iDdataPrep.SFDC.ListViewRecordColumn []'转换为'iDdataPrep.SFDC.ListViewRecordColumn'

错误CS0029:无法将类型'iDdataPrep.SFDC.ListViewRecordColumn'隐式转换为'iDdataPrep.SFDC.ListViewRecordColumn []'

错误CS0029:无法将类型'iDdataPrep.SFDC.ListViewRecordColumn'隐式转换为'iDdataPrep.SFDC.ListViewRecordColumn []'

这是我的代码:

public static void sfLogin()
    {
        string userName = "***";
        string password = "***";
        string securityToken = "***";

        SFDC.SforceService sfdcBinding = null;
        SFDC.LoginResult currentLoginResult = null;
        sfdcBinding = new SFDC.SforceService();
        try
        {
            currentLoginResult = sfdcBinding.login(userName, password);
        }
        catch (System.Web.Services.Protocols.SoapException ex)
        {
            sfdcBinding = null;
            MessageBox.Show(ex.Message);
        }
        catch(Exception ex)
        {
            sfdcBinding = null;
            MessageBox.Show(ex.Message);
        }
        sfdcBinding.Url = currentLoginResult.serverUrl;
        sfdcBinding.SessionHeaderValue = new SFDC.SessionHeader();
        sfdcBinding.SessionHeaderValue.sessionId = currentLoginResult.sessionId;
    }

3 个答案:

答案 0 :(得分:1)

由于this link中描述的.NET的XmlSerializer中的错误,某些与Salesforce的.Net集成失败了。

解决方法是将以下元素添加到Enterprise.WSDL.XML文件中:

<xsd:attribute name="tmp" type="xsd:string" />
ListViewRecord部分中的

。您的Enterprise.WSDL.XML应如下所示:

<complexType name="ListViewRecord">
  <sequence>
    <element name="columns" type="tns:ListViewRecordColumn" maxOccurs="unbounded"/>
  </sequence>
  <b>
    <xsd:attribute name="tmp" type="xsd:string" />
  </b>
</complexType>

this link中查看更多内容。

答案 1 :(得分:0)

我只是遇到了这个问题。这是我使用过的解决方法。在从wsdl(例如partner.wsdl)生成代理文件之前,请编辑该文件并将虚拟字段添加到ListViewRecord定义中。

<complexType name="ListViewRecord">
    <sequence>
        <element name="columns"                  type="tns:ListViewRecordColumn" minOccurs="1" maxOccurs="unbounded"/>
        <element name="dummy"                    type="xsd:int"/>
    </sequence>
</complexType>

使用wsdl.exe生成代理文件时,它将正确生成类ListViewRecord和ListViewRecordColumn。然后从生成的代码中删除虚拟字段,并将按原样定义类和属性。

public partial class ListViewRecord {

    private ListViewRecordColumn[] columnsField;

    /// ** delete this member variable **
    private int dummyField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("columns")]
    public ListViewRecordColumn[] columns {
        get {
            return this.columnsField;
        }
        set {
            this.columnsField = value;
        }
    }

    /// ** delete this property **
    public int dummy {
        get {
            return this.dummyField;
        }
        set {
            this.dummyField = value;
        }
    }
}

答案 2 :(得分:0)

ListViewRecordColumn[][]中有两个对Reference.cs的引用。

将它们都更改为ListViewRecordColumn[]