SoapClient.SendRequestResponse 知道传出请求 SOAP 标头中的 MessageID,并且在接收到带有与原始 MessageID 匹配的 RelatesTo 值的消息之前不会完成调用。因此,如果您正在制作响应程序/存根,您需要从请求中解析出 MessageID 并将其注入响应的 SOAP 标头中的 RelatesTo 字段。
有点奇怪的是,它不仅仅在任何有效的 SOAP 消息之后返回,并且由于不匹配而引发了一个期望。也许这是 SOAP Web 服务标准的一部分。我没有调查它。
例子:
要求:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance/" xmlns:xsd="http://www.w3.org/2001/XMLSchema/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility">
<soap:Header>
<wsa:MessageID soap:mustUnderstand="1">uuid:20E6C5D8-2E0D-48D0-863D-7789D2CA37A2</wsa:MessageID>
...
回复:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility">
<soap:Header>
<wsa:MessageID SOAP-ENV:mustUnderstand="1" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">uuid:bb1cf43050739c45:248138d0:1328e31d4e2:-5cf4</wsa:MessageID>
<wsa:RelatesTo RelationshipType="wsa:Reply" SOAP-ENV:mustUnderstand="1" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">uuid:20E6C5D8-2E0D-48D0-863D-7789D2CA37A2</wsa:RelatesTo>
...
The RelatesTo value is the same as the MessageID value in the request. The MessageID in the response is new and unique because the response message is not the request message.