C# MS VS WebReference 类型的变量

C# MS VS WebReference type of variable

我想从一个网络服务中读取值(这里是 WSDL)。

我的代码在这里:

protected void Button1_Click(object sender, EventArgs e)
{
    var ahoj = new string[] { 28156609.ToString() };
    InformaceOPlatciType[] platceinfo;

    mfcrDPH.rozhraniCRPDPH srv = new mfcrDPH.rozhraniCRPDPH();
    StatusType status = srv.getStatusNespolehlivyPlatce(ahoj, out platceinfo);

    for (int i = 0; i < platceinfo.Length; i++)
   {
        mfcrDPH.InformaceOPlatciType info = platceinfo[i];
        Label1.Text = info.dic;
        Label2.Text = info.nespolehlivyPlatce;
   }
}

mfcrDPH 是 MS 内部的 WebReference Visual Studio。

问题出在值 info.nespolehlivyPlatce 上。值 info.dic 工作正常。我不明白如何修复它,因为在 WSDL 中我看到两个变量在原理上是相同的——两者的类型都是 simple.

对于 label2.Text 我得到一个错误:

Error 3 Cannot implicitly convert type 'mfcrDPH.NespolehlivyPlatceType' to 'string' D:\Tvorba\vs2010\WebTelefony\DPH\DHP_Dash2.aspx.cs 27 27 WebTelefony

这是带有图形信息的图片:Picture1

是否可以帮助我解决为什么会收到此类错误消息?

阅读错误并尝试理解它。此代码:

Label2.Text = info.nespolehlivyPlatce;

尝试将 NespolehlivyPlatceType 类型的对象分配给 string 类型的 属性,这是不兼容的。所以那是行不通的。

您需要在 NespolehlivyPlatceType 类型上找到您可以使用的 属性。展开 XSD/WSDL 中的 simpleType,使用 IntelliSense 或检查对象浏览器以查看 class 上哪些属性可用,哪些是字符串,或可转换为它。例如:

Label2.Text = info.nespolehlivyPlatce.ID;

错误消息是由类型不匹配生成的。在 Wsdl 中,文档使用 tns(此名称 space)来指代字符串以外的类型。这就是您在代码中看到类型转换错误的原因。您要么需要将类型从字符串更改为匹配 wsql 类型,要么需要进行一些转换或类型转换