由于保护级别,变量无法访问

时间:2016-05-25 12:45:44

标签: vb.net

我正在写一篇VB.Net

Private Function generateXMLSchema()
    Dim generatedXmlSchema As String = "<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:glob="http://sap.com/xi/SAPGlobal20/Global"><soapenv:Header/>" & _
        "<soapenv:Body>" & _
            "<glob:RouteBundleMaintainRequest_sync_V1>" & _
                "<Route actionCode="01">" & _
                    "<Name>tEST 250502</Name>" & _
                    "<RouteTypeCode>2</RouteTypeCode>" & _
                "</Route>" & _
            "</glob:RouteBundleMaintainRequest_sync_V1>" & _
        "</soapenv:Body>" & _
    "</soapenv:Envelope>"

    Return generatedXmlSchema
End Function

Return generatedXmlSchema我收到错误: generatedXmlSchema未声明。由于保护级别

,它可能无法访问

有人可以告诉我这个问题吗?

更新了Double Quote,仍然是同样的错误

Private Function generateXMLSchema()
    Dim genXmlSchema As String = "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:glob=""http://sap.com/xi/SAPGlobal20/Global"><soapenv:Header/>" & _
        "<soapenv:Body>" & _
            "<glob:RouteBundleMaintainRequest_sync_V1>" & _
                "<Route actionCode="01">" & _
                    "<Name>tEST 250502</Name>" & _
                    "<RouteTypeCode>2</RouteTypeCode>" & _
                "</Route>" & _
            "</glob:RouteBundleMaintainRequest_sync_V1>" & _
        "</soapenv:Body>" & _
    "</soapenv:Envelope>"

    Return genXmlSchema
End Function

1 个答案:

答案 0 :(得分:2)

您必须将每次出现的引号双引号作为字符串分隔符:

"http://schemas.xmlsoap.org/soap/envelope/" -> ""http://schemas.xmlsoap.org/soap/envelope/""

"http://sap.com/xi/SAPGlobal20/Global" -> ""http://sap.com/xi/SAPGlobal20/Global""

"01" -> ""01""

说,这个函数是Private所以必须在它所属的Class内调用

以上所有内容如下:

Public Class Class1

    Sub main()
        Console.WriteLine(generateXMLSchema())
    End Sub

    Private Function generateXMLSchema()
        Dim generatedXmlSchema As String = "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:glob=""http://sap.com/xi/SAPGlobal20/Global""><soapenv:Header/>" &
            "<soapenv:Body>" &
                "<glob:RouteBundleMaintainRequest_sync_V1>" &
                    "<Route actionCode=""01"">" &
                        "<Name>tEST 250502</Name>" &
                        "<RouteTypeCode>2</RouteTypeCode>" &
                    "</Route>" &
                "</glob:RouteBundleMaintainRequest_sync_V1>" &
            "</soapenv:Body>" &
        "</soapenv:Envelope>"

        Return generatedXmlSchema
    End Function

End Class