我尝试与网络服务进行通信,并构建了一个发送给服务器的请求。但是,Web服务并没有获得我设置的所有属性。
wsdl中的操作是:
<operation name="GetCommunityPeopleIds">
<soap:operation soapAction="GetCommunityPeopleIds" style="document" />
<xrd:version>v1</xrd:version>
<input>
<soap:body parts="body" use="literal" />
<soap:header message="tns:standardheader" part="consumer" use="literal" />
<soap:header message="tns:standardheader" part="producer" use="literal" />
<soap:header message="tns:standardheader" part="userId" use="literal" />
<soap:header message="tns:standardheader" part="id" use="literal" />
<soap:header message="tns:standardheader" part="service" use="literal" />
</input>
<output>
<soap:body parts="body" use="literal" />
<soap:header message="tns:standardheader" part="consumer" use="literal" />
<soap:header message="tns:standardheader" part="producer" use="literal" />
<soap:header message="tns:standardheader" part="userId" use="literal" />
<soap:header message="tns:standardheader" part="id" use="literal" />
<soap:header message="tns:standardheader" part="service" use="literal" />
</output>
</operation>
相关的两条消息是:
<message name="GetCommunityPeopleIds">
<part name="body" element="tns:GetCommunityPeopleIds" />
</message>
<message name="GetCommunityPeopleIdsResponse">
<part name="body" element="tns:GetCommunityPeopleIdsResponse" />
</message>
这些是元素:
<element name="GetCommunityPeopleIds">
<complexType>
<sequence>
<element name="request" type="tns:communityPeopleIdsRequest" />
</sequence>
</complexType>
</element>
<element name="GetCommunityPeopleIdsResponse">
<complexType>
<sequence>
<element name="faultCode" type="xrd:faultCode" nillable="true" />
<element name="faultString" type="xrd:faultString" nillable="true" />
<element name="request" type="tns:communityPeopleIdsRequest" />
<element name="response">
<complexType>
<sequence>
<element minOccurs="0" name="PeopleIds" nillable="true" type="tns:ArrayOfPersonIds" />
<element minOccurs="0" name="TotalCount" type="int" />
</sequence>
</complexType>
</element>
</sequence>
</complexType>
</element>
引用类型communityPeopleIdsRequest
定义如下:
<complexType name="communityPeopleIdsRequest">
<sequence>
<element name="requestBody">
<complexType>
<sequence>
<element minOccurs="0" name="Count" type="int" />
<element minOccurs="0" name="ModifiedBefore" type="dateTime" />
<element minOccurs="0" name="ModifiedSince" type="dateTime" />
<element minOccurs="0" name="SortDescriptions" type="tns:ArrayOfSortDescription" />
<element minOccurs="0" name="StartIndex" type="int" />
</sequence>
</complexType>
</element>
<element name="requestHeader">
<complexType>
<sequence>
<element name="token" type="string">
<annotation>
<appinfo>
<xrd:title xml:lang="en">a fedAuth token</xrd:title>
</appinfo>
</annotation>
</element>
</sequence>
</complexType>
</element>
</sequence>
</complexType>
我的问题是,因为我引用了这个web服务并从vb.net表单应用程序调用它;当我这样做时,webservice所有者告诉我,当我调用webservice时,我的属性没有传递给webservice - requestBody的所有属性都是空的。
这是我用于构建对webservice的请求的代码,其中实际上在requestBody中设置了日期值:
Dim cl = New ElktestService.CrsPortTypeClient("Test")
Dim consumer, producer, userid, id, service As String
consumer = "consumername"
producer = "producername"
userid = "user 1"
id = "123456789"
service = "producername.GetCommunityPeopleIds.v1"
'Set token in header
Dim hdr As New communityPeopleIdsRequestRequestHeader
hdr.token = tempToken
'Set dates í body
Dim bdy As New communityPeopleIdsRequestRequestBody
bdy.ModifiedSince = dtFromDate.Value
bdy.ModifiedBefore = dtToDate.Value
'set header & body into the request
Dim req = New communityPeopleIdsRequest
req.requestHeader = hdr
req.requestBody = bdy
'Set request property of the getCommunityPeopleIds
Dim ppid = New GetCommunityPeopleIds()
ppid.request = req
'Now let's try to deserialze the xml that I send, so I can see what is being passed
Dim serxml As System.Xml.Serialization.XmlSerializer = New System.Xml.Serialization.XmlSerializer(GetType(ElktestClient.ElktestService.communityPeopleIdsRequest))
Dim ms As New System.IO.MemoryStream
serxml.Serialize(ms, req)
Dim xml As String = System.Text.Encoding.UTF8.GetString(ms.ToArray())
Dim rsp = cl.GetCommunityPeopleIds(consumer, producer, userid, id, service, ppid)
If rsp.faultCode Is Nothing And rsp.faultString Is Nothing Then
For Each itm In rsp.response.PeopleIds
Me.lstIds.Items.Add(itm.PublicId)
Next
End If
...以下是反序列化的xml告诉我发送的内容(requestBody为空):
<?xml version="1.0"?>
<communityPeopleIdsRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<requestBody />
<requestHeader>
<token>FedAuth=7uPD........2lvbj0i+; path=/Crs/; secure; HttpOnly</token>
</requestHeader>
</communityPeopleIdsRequest>
我还检查了断点,就在反序列化代码之前,日期参数的内容确实在运行时设置为正确的值。
我遗漏的显而易见的事情是 - 为什么没有设置日期以及为什么requestBody为空?关于要检查的事情的任何想法?