【问题标题】:what is the difference between xml codexml代码有什么区别
【发布时间】:2014-05-13 13:42:08
【问题描述】:

我一直在做webservice,遇到了这个问题:

有什么区别:

<string xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://companyx.net/" xsi:nil="true"/>

<string xmlns="http://companyx.net/">[]</string>

询问的原因是因为我编码(尝试)了一个 Web 服务,如果我调用它,我会得到 <string xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://companyx.net/" xsi:nil="true"/> 和我查看的其他 Web 服务方法在调用时返回 <string xmlns="http://companyx.net/">[]</string>。我知道第二种方法返回一个项目数组,我需要这样做。我想返回一个联系人列表。

我的网络服务代码:

 <WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=True)> _
    Public Function ContactGet(ByVal searchField As String) As String

        Dim objSearch As New ArrayList
        Dim objSearching As New Search
        Dim intResult As Integer

        Try

            intResult = objSearching.SearchByKeyword(searchField, Session("Person"), Session("Office"), Session("Organisation"), _
                                                  Session("Role"), companyx.CXMyProperty.Search.enmSearchType.enmContact, objSearch)


                Dim objContact As New Person
                Dim dt As New DataTable("Contacts")

                Dim col_Name As New DataColumn("Name", GetType(String))
                dt.Columns.Add(col_Name)

                Dim col_Mobile As New DataColumn("Mobile", GetType(String))
                dt.Columns.Add(col_Mobile)

                Dim col_Office As New DataColumn("ContactNum", GetType(String))
                dt.Columns.Add(col_Office)

                Dim col_Category As New DataColumn("Category", GetType(String))
                dt.Columns.Add(col_Category)

                Dim dr As DataRow

                'add new row to datatable
                For Each objSearching In objSearch
                    dr = dt.NewRow()
                    dr("Name") = objContact.FullName
                    dr("Mobile:") = objContact.MobileNumber
                    dr("ContactNum") = objContact.OfficeNumber
                    dr("Category") = objContact.PersonRelationshipType
                    dt.Rows.Add(dr)
                Next

                Dim serializer As New JavaScriptSerializer()
                Dim rows As New List(Of Dictionary(Of String, Object))()
                Dim row As Dictionary(Of String, Object) = Nothing

                'serialize dt row to json output
                For Each drow As DataRow In dt.Rows
                    row = New Dictionary(Of String, Object)()
                    For Each col As DataColumn In dt.Columns
                        row.Add(col.ColumnName, dr(col))
                    Next
                    rows.Add(row)
                Next

                Dim str_json = JsonConvert.SerializeObject(dt, Formatting.Indented)

                Return str_json
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

我不确定我是否正确编码了 Web 服务。对此非常陌生。

【问题讨论】:

  • ASMX 是一项遗留技术,不应用于新开发。 WCF 或 ASP.NET Web API 应该用于 Web 服务客户端和服务器的所有新开发。一个提示:微软已经在 MSDN 上停用了ASMX Forum

标签: xml web-services asmx


【解决方案1】:

它们之间的区别在于,在一种情况下,字符串元素具有 xsi:nil 属性,而在另一种情况下,它具有“[]”文本节点子节点。

这些可能有也可能没有相似或相同的语义:您需要询问 companyx.net 上的人,他们设计了这个词汇表。

【讨论】:

    猜你喜欢
    • 2018-11-13
    • 2012-09-27
    • 2014-03-21
    • 1970-01-01
    • 2015-05-30
    • 2011-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多