当请求有效时,SoapUI将错误视为格式错误的请求

时间:2018-01-11 20:29:00

标签: xml wcf soap soapui xml-namespaces

这是我的.net代码生成的xml片段,发送到第三方soap服务端点。

<?xml version="1.0" encoding="utf-16"?>
  <ProgramInterface 
   xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">  
    <vnsState_request xmlns="http://www.statewide.Request.com">
.....
....
...

这通过代码工作,但当我把我从SoapUI中的调试断点中提取的完全相同的请求发送到同一服务时,它返回XML格式错误,如下所示

<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>Malformed SOAP message</faultstring>

当我为同一操作生成样本请求时,我在生成的请求XML中看到了这种差异

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:vns="http://www.statewide.Request.com">
   <soapenv:Header/>
   <soapenv:Body>
      <vns:VNSSTATEOperation>
         <vns:vnsState_request>

为什么SoapUI需要这些额外的标签,为什么它不能使用我的.Net代码生成的请求?为什么它需要vns:预先设置每个元素以及这些新元素?

<soapenv:Envelope >
   <soapenv:Header/>
   <soapenv:Body>

1 个答案:

答案 0 :(得分:2)

  1. 关于额外标记:如果要从任何客户端访问SOAP服务,则需要SOAP标头。您可以找到更多详细信息here
  2. 关于前缀:如果使用了.net案例中的默认命名空间,则不需要。在SoapUI中,它使用显式名称空间,因此使用prefix。您可以找到有关名称空间 here
  3. 的更多详细信息

    例如,举个例子。以下两者都是一样的。

    <vnsState_request xmlns="http://www.statewide.Request.com">
    <!--the above one is using default namespace -->
    

    <ns:vnsState_request xmlns:ns="http://www.statewide.Request.com">
    <!--using explicit namespace "ns", hence the same is prefixed for the tag -->
    

    如果你看看SoapUI中的那个,它在第一行中添加了命名空间。所以,它正如你所展示的那样使用。

    希望这有帮助。

相关问题