我一直致力于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
我不确定我是否正确编码了网络服务。对此非常陌生。
答案 0 :(得分:0)
它们之间的区别在于,在一种情况下,字符串元素具有xsi:nil属性,而在另一种情况下,它具有&#34; []&#34;文本节点子。
这些可能有也可能没有相似或相同的语义:你需要询问设计这个词汇表的companyx.net上的人。