0

我正在为 Staeubli 机器人控制器 (CS8) 编写接口。在我尝试请求一些 IO 信息之前,一切都很顺利。请求以 SOAP_EOF 结束。我尝试了其他一些请求,它们都可以正常工作。所以我捕获了发送/接收的包,好请求和坏请求之间的唯一区别是响应的 mime 类型。这是坏的请求/响应:

要求

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
    xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"
    xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:ns3="http://www.w3.org/2004/08/xop/include"
    xmlns:ns4="http://www.w3.org/2004/11/xmlmime"
    xmlns:ns5="http://tempuri.org/xmlmime.xsd"
    xmlns:ns1="CS8ServerV0"
    xmlns:ns2="urn:CS8ServerV1"
    xmlns:ns6="urn:CS8ServerV2" 
    xmlns:ns7="urn:CS8ServerV3">
    <SOAP-ENV:Header>
        <ns1:sessionId SOAP-ENV:mustUnderstand="true">18638456</ns1:sessionId>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <ns6:getAllPhysicalIos></ns6:getAllPhysicalIos>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

回复

--==pj+EhsWuSQJxx7przmb8HM+ZkeNcG3HezSNID7LmfDa9J4lfdUL8W1F7TNJK==
Content-Type: application/xop+xml; charset=utf-8; type="application/soap+xml; charset=utf-8"
Content-Transfer-Encoding: binary
Content-ID: <SOAP-ENV:Envelope>

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
    xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"
    xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:SCSV0="CS8ServerV0"
    xmlns:xop="http://www.w3.org/2004/08/xop/include"
    xmlns:xmlmime="http://tempuri.org/xmlmime.xsd"
    xmlns:SCSV1="urn:CS8ServerV1"
    xmlns:SCSV2="urn:CS8ServerV2">
    <SOAP-ENV:Header>
        <SCSV0:sessionId>18638456</SCSV0:sessionId>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <SCSV2:getAllPhysicalIosResponse>
            <data xmlmime:contentType="text/xml">
                <data><xop:Include href="cid:id1"/></data>
            </data>
        </SCSV2:getAllPhysicalIosResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

--==pj+EhsWuSQJxx7przmb8HM+ZkeNcG3HezSNID7LmfDa9J4lfdUL8W1F7TNJK==
Content-Type: text/xml
Content-Transfer-Encoding: binary
Content-ID: <id1>

<?xml version="1.0" encoding="utf-8"?>
<PhysicalIos xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.staubli.com/robotics/PhysicalIos/1" >
    <Io name="usrIn0" desc="" type="din" />
    <Io name="usrIn1" desc="" type="din" />
    <Io name="MOTOR_1_3_5" desc="" type="din" />
    <Io name="MOTOR_2_4_6" desc="" type="din" />
    <Io name="CASTING" desc="" type="din" />
    <Io name="DSI_BOARD" desc="" type="din" />
    <Io name="GLOBAL_PTC" desc="" type="din" />
    <Io name="fIn0" desc="" type="din" />
    <Io name="fIn1" desc="" type="din" />
    <Io name="SECTEUR_OK" desc="" type="din" />
    <Io name="valve1" desc="" type="dout" />
    <Io name="valve2" desc="" type="dout" />
    <Io name="fOut0" desc="" type="dout" />
    <Io name="CBT_TEMP" desc="" type="ain" />
    <Io name="CPU_TEMP" desc="" type="ain" />
    <Io name="Socket\test" desc="" type="socketClient" />
</PhysicalIos>

--==pj+EhsWuSQJxx7przmb8HM+ZkeNcG3HezSNID7LmfDa9J4lfdUL8W1F7TNJK==--

SOAP 错误

SOAP 1.2 fault: SOAP-ENV:Sender [no subcode]
"End of file or no input: Operation interrupted or timed out"
Detail: [no detail] 

SOAP 错误代码= SOAP_EOF (== -1)

也许有人看到我的错?

如果缺少任何信息,请随时发表评论。

提前致谢!

编辑1

我还记录了 gSOAP 连接。这是相关的日志条目:

HTTP status: HTTP/1.1 200 OK
HTTP header: Server: gSOAP/2.7
HTTP header: Content-Type: multipart/related; boundary="==IhAUx7qlRoBMWpLHXMvxVdaVBbhA+poanGC1U/anZjRVQ4oRZshmeOhwc+Zx=="; type="application/xop+xml"; start="<SOAP-ENV:Envelope>"; start-info="application/soap+xml; charset=utf-8"
../soaptest/source/stdsoap2.cpp(7330): malloc(224) = 0xbe6290
../soaptest/source/stdsoap2.cpp(7330): malloc(88) = 0xab3170
../soaptest/source/stdsoap2.cpp(7330): malloc(40) = 0xbe5ae0
HTTP header: Transfer-Encoding: chunked
HTTP header: Connection: keep-alive
Finished HTTP header parsing, status = 200
Keep alive connection = 1
Getting chunk size (idx=307 len=307)
Read 5 bytes from socket=21/fd=0
Chunk size = 81E (hex)
Moving buf len to idx=5 len=2083 (81E)
Passed end of buffer for chunked HTTP (0 bytes left)
Getting chunk: read 1448 bytes
../soaptest/source/stdsoap2.cpp(7330): malloc(96) = 0xab2ef0
MIME header: Content-Type: application/xop+xml; charset=utf-8; type="application/soap+xml; charset=utf-8"
../soaptest/source/stdsoap2.cpp(7330): malloc(104) = 0xbe6380
MIME header: Content-Transfer-Encoding: binary
MIME header: Content-ID: <SOAP-ENV:Envelope>
../soaptest/source/stdsoap2.cpp(7330): malloc(40) = 0xbe63f0
XML PI <?xml version="1.0" encoding="UTF-8"?>
Switching to utf-8 encoding
../soaptest/source/stdsoap2.cpp(10357): malloc(62) = 0xbe5d60
Enlarging look-aside buffer to append data, old size=0, new size=256
../soaptest/source/stdsoap2.cpp(10160): malloc(256) = 0xaf89e0
../soaptest/source/stdsoap2.cpp(10412): malloc(256) = 0xaf8c00
../soaptest/source/stdsoap2.cpp(2735): malloc(40) = 0xbe64e0
Push namespace binding (level=0) 'SOAP-ENV' 'http://www.w3.org/2003/05/soap-envelope'
Push OK ('SOAP-ENV' matches 'SOAP-ENV' in namespace table)
../soaptest/source/stdsoap2.cpp(10357): malloc(62) = 0xbe5b40
../soaptest/source/stdsoap2.cpp(10412): malloc(256) = 0xbe5340
../soaptest/source/stdsoap2.cpp(2735): malloc(40) = 0xbe65a0
Push namespace binding (level=0) 'SOAP-ENC' 'http://www.w3.org/2003/05/soap-encoding'
Push OK ('SOAP-ENC' matches 'SOAP-ENC' in namespace table)
../soaptest/source/stdsoap2.cpp(10357): malloc(57) = 0xbe5920
../soaptest/source/stdsoap2.cpp(10412): malloc(256) = 0xbe5560
../soaptest/source/stdsoap2.cpp(2735): malloc(35) = 0xbe6660
Push namespace binding (level=0) 'xsi' 'http://www.w3.org/2001/XMLSchema-instance'
Push OK ('xsi' matches 'xsi' in namespace table)
../soaptest/source/stdsoap2.cpp(10357): malloc(57) = 0xbe5700
../soaptest/source/stdsoap2.cpp(10412): malloc(256) = 0xbe5780
../soaptest/source/stdsoap2.cpp(2735): malloc(35) = 0xbe6720
Push namespace binding (level=0) 'xsd' 'http://www.w3.org/2001/XMLSchema'
Push OK ('xsd' matches 'xsd' in namespace table)
../soaptest/source/stdsoap2.cpp(10357): malloc(59) = 0xbe54e0
../soaptest/source/stdsoap2.cpp(10412): malloc(256) = 0xbe59a0
../soaptest/source/stdsoap2.cpp(2735): malloc(37) = 0xbe67e0
Push namespace binding (level=0) 'SCSV0' 'CS8ServerV0'
Push OK ('SCSV0' matches 'ns1' in namespace table)
../soaptest/source/stdsoap2.cpp(10357): malloc(57) = 0xaf8da0
../soaptest/source/stdsoap2.cpp(10412): malloc(256) = 0xbe5bc0
../soaptest/source/stdsoap2.cpp(2735): malloc(35) = 0xbe68a0
Push namespace binding (level=0) 'xop' 'http://www.w3.org/2004/08/xop/include'
Push OK ('xop' matches 'ns3' in namespace table)
../soaptest/source/stdsoap2.cpp(10357): malloc(61) = 0xaf8b80
../soaptest/source/stdsoap2.cpp(10412): malloc(256) = 0xbe5de0
../soaptest/source/stdsoap2.cpp(2735): malloc(39) = 0xbe6960
Push namespace binding (level=0) 'xmlmime' 'http://tempuri.org/xmlmime.xsd'
Push OK ('xmlmime' matches 'ns5' in namespace table)
../soaptest/source/stdsoap2.cpp(10357): malloc(59) = 0xab2e70
../soaptest/source/stdsoap2.cpp(10412): malloc(256) = 0xbe6000
../soaptest/source/stdsoap2.cpp(2735): malloc(37) = 0xbe6a20
Push namespace binding (level=0) 'SCSV1' 'urn:CS8ServerV1'
Push OK ('SCSV1' matches 'ns2' in namespace table)
../soaptest/source/stdsoap2.cpp(10357): malloc(59) = 0xbe6a80
../soaptest/source/stdsoap2.cpp(10412): malloc(256) = 0xab3030
../soaptest/source/stdsoap2.cpp(2735): malloc(37) = 0xbe6b30
Push namespace binding (level=0) 'SCSV2' 'urn:CS8ServerV2'
Push OK ('SCSV2' matches 'ns6' in namespace table)
Tags and (default) namespaces match: 'SOAP-ENV:Envelope' 'SOAP-ENV:Envelope'
Begin element found (level=1) 'SOAP-ENV:Envelope'='SOAP-ENV:Envelope'
../soaptest/source/stdsoap2.cpp(14903): malloc(40) = 0xbe6b90
Tags and (default) namespaces match: 'SOAP-ENV:Header' 'SOAP-ENV:Header'
Begin element found (level=2) 'SOAP-ENV:Header'='SOAP-ENV:Header'
Enter id='' type=296 loc=(nil) size=8 level=0
../soaptest/source/stdsoap2.cpp(7330): malloc(32) = 0xbe6bf0
Tags and (default) namespaces match: 'SCSV0:sessionId' 'ns1:sessionId'
Begin element found (level=3) 'SCSV0:sessionId'='ns1:sessionId'
Reverting to last element 'SCSV0:sessionId' (level=2)
Tags and (default) namespaces match: 'SCSV0:sessionId' 'ns1:sessionId'
Begin element found (level=3) 'SCSV0:sessionId'='ns1:sessionId'
Enter id='' type=206 loc=(nil) size=4 level=0
../soaptest/source/stdsoap2.cpp(7330): malloc(24) = 0xbe6c50
Element content value='18714240'
End element found (level=3) 'SCSV0:sessionId'='ns1:sessionId'
End element found (level=2) 'SOAP-ENV:Header'='SOAP-ENV:Header'
Tags and (default) namespaces match: 'SOAP-ENV:Body' 'SOAP-ENV:Body'
Begin element found (level=2) 'SOAP-ENV:Body'='SOAP-ENV:Body'
Tags and (default) namespaces match: 'SCSV2:getAllPhysicalIosResponse' 'ns6:getAllPhysicalIosResponse'
Begin element found (level=3) 'SCSV2:getAllPhysicalIosResponse'='ns6:getAllPhysicalIosResponse'
Enter id='' type=166 loc=0xab3010 size=24 level=0
../soaptest/source/stdsoap2.cpp(10357): malloc(67) = 0xbe6ca0
../soaptest/source/stdsoap2.cpp(10412): malloc(256) = 0xbe6d20
Tags match: 'data' 'data'
Begin element found (level=4) 'data'='data'
Reverting to last element 'data' (level=3)
soap_instantiate_ns6__MimeData(-1, , )
../soaptest/source/stdsoap2.cpp(7617): malloc(32) = 0xbe6e60
Instantiated location=0xbe6ec0
Tags match: 'data' 'data'
Begin element found (level=4) 'data'='data'
Enter id='' type=97 loc=0xbe6ec0 size=80 level=0
Tags and (default) namespaces match: 'xmlmime:contentType' 'ns5:contentType'
../soaptest/source/stdsoap2.cpp(7330): malloc(32) = 0xbe6f20
soap_instantiate_std__string(-1, , )
../soaptest/source/stdsoap2.cpp(7617): malloc(32) = 0xbe6f80
Instantiated location=0xbe6fe0
Tags match: 'data' 'data'
Begin element found (level=5) 'data'='data'
Enter id='' type=10 loc=0xbe6ec8 size=56 level=0
../soaptest/source/stdsoap2.cpp(10357): malloc(52) = 0xbe7030
../soaptest/source/stdsoap2.cpp(10412): malloc(256) = 0xbe70a0
Tags 'xop:Include' and 'xop:Include' match but namespaces differ
End element found (level=5) 'data'='data'
End element found (level=4) 'SCSV2:getAllPhysicalIosResponse'='data'
End element found (level=3) 'SOAP-ENV:Body'='ns6:getAllPhysicalIosResponse'
End element found (level=2) 'SOAP-ENV:Envelope'='SOAP-ENV:Body'
XML PI <?xml version="1.0" encoding="utf-8"?>
Switching to utf-8 encoding
Getting chunk: read 630 bytes
Read 7 bytes (chunked) from socket 21
Getting chunk size (idx=0 len=7)
Chunk size = 0 (hex)
End of chunked message
Shutdown socket 21 how=2
Close socket 21
soap_instantiate_SOAP_ENV__Fault(-1, , )
../soaptest/source/stdsoap2.cpp(7617): malloc(32) = 0xbe71e0
Instantiated location=0xbe7240
soap_instantiate_SOAP_ENV__Code(-1, , )
../soaptest/source/stdsoap2.cpp(7617): malloc(32) = 0xbe7290
Instantiated location=0xbe72f0
soap_instantiate_SOAP_ENV__Reason(-1, , )
../soaptest/source/stdsoap2.cpp(7617): malloc(32) = 0xbe7310
Instantiated location=0xbe7370

解决方案

所以我逐行研究了日志文件,发现了一些有趣的东西。相关线路:

Tags 'xop:Include' and 'xop:Include' match but namespaces differ

这意味着soap 不会解析响应中的idx 字段。相反,它使用:

MIME header: Content-ID: <SOAP-ENV:Envelope>

这绝对是错误的。

所以我想,服务器使用的 XML 命名空间一定有问题。通过忽略名称空间错误,它可以工作。

我使用以下 IO_MODE 进行套接字连接:#define MY_IO_MODE (IO_MODE | SOAP_ENC_MTOM | SOAP_XML_IGNOREN)

现在看起来好多了:

MIME header: Content-ID: <id1>

尽管知道忽略格式/名称空间错误不是好的编程风格,但我别无选择,只能保留它们,因为我对服务器端没有影响。

感谢所有读者!

4

1 回答 1

0

我看到这是一个 HTTP 保持连接。当下一条消息没有到达并且连接被对等方关闭时,您将收到一个 EOF。最好是设置 IO 超时(connect_timeout、send_timeout、recv_timeout)并在 EOF 为 soap.errnum == 0 后检查,这意味着连接超时。另外,请确保使用最新的 2.8.16 版本。MIME 附件的问题似乎在某些版本之前发生过,但已得到解决。

于 2013-11-16T20:59:44.207 回答