在vb.net中序列化soap响应

时间:2016-03-23 07:04:35

标签: vb.net soap

  Using response As WebResponse = request.GetResponse()
            Using rd As New StreamReader(response.GetResponseStream())
                Dim soapResult As String = rd.ReadToEnd()
                SerializeCollection(soapResult)

soapResult生成以下内容:

  <?xml version="1.0" encoding="UTF-8"?>
 <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <SOAP-ENV:Body>
  <createShipmentResponse xmlns="http://www.royalmailgroup.com/api/ship/V2">
     <integrationHeader>
        <dateTime xmlns="http://www.royalmailgroup.com/integration/core/V1">2016-03-23T06:55:32</dateTime>
        <version xmlns="http://www.royalmailgroup.com/integration/core/V1">2</version>
        <identification xmlns="http://www.royalmailgroup.com/integration/core/V1">
           <applicationId>RMG-API-G-01</applicationId>
           <transactionId>730222611</transactionId>
        </identification>
     </integrationHeader>
     <integrationFooter>
        <errors xmlns="http://www.royalmailgroup.com/integration/core/V1">
           <error>
              <errorCode>E1105</errorCode>
              <errorDescription>The countryCode specified is not valid</errorDescription>
           </error>
           <error>
              <errorCode>E1001</errorCode>
              <errorDescription>Postcode AA9 0AA invalid</errorDescription>
           </error>
        </errors>
        <warnings xmlns="http://www.royalmailgroup.com/integration/core/V1">
           <warning>
              <warningCode>W0036</warningCode>
              <warningDescription>E-mail option not selected so e-mail address will be ignored</warningDescription>
           </warning>
           <warning>
              <warningCode>W0035</warningCode>
              <warningDescription>SMS option not selected so Telephone Number will be ignored</warningDescription>
           </warning>
        </warnings>
     </integrationFooter>
      </createShipmentResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我正在使用此方法序列化此响应:

Private Sub SerializeCollection(filename As String)
    Dim Emps As createShipmentResponse = New createShipmentResponse()
    ' Note that only the collection is serialized -- not the 
    ' CollectionName or any other public property of the class.
    Dim x As XmlSerializer = New XmlSerializer(GetType(createShipmentResponse))
    Dim writer As TextWriter = New StreamWriter(filename)
    x.Serialize(writer, Emps)
    writer.Close()
End Sub

但我遇到此错误:路径中的字符非法 那是什么意思 ?我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您的SerializeCollection()方法需要将文件路径序列化为文件。您目前正在传递回复的内容,这就是它无效的原因。

如果你自己没有写过这个方法,我想你还没找到你想要的东西。

这是应该如何调用该方法的示例:

SerializeCollection("C:\Users\Vincent\Desktop\Hello.bin") 'The extension doesn't need to be '.bin', but it's an example.

该方法目前无法获得您的回复,因为您应该添加第二个参数。

由于我不熟悉Soap序列化,我恐怕无法帮助你。