每个soap请求标签中的名称空间前缀

时间:2019-11-13 15:40:57

标签: java xml web-services soap

将数据传输到Web服务肥皂时出现问题。如果在请求中使用名称空间前缀,则数据不会进入ComplexType0类。

var books = new List<Book>();
for (int i = 1; i < 4; i++)
{
    books.Add(new Book
    {
        new Book { Id = i , Author = $"New Author {i}"}
    });
}

var mockBookRepository = new Mock<IBookRepository>();
mockBookRepository 
    .Setup(x => x.Query())
    .Returns(books.AsQueryable());

如果您使用这样的请求,则数据正确无误。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <tns:method1 xmlns:tns="http://test.com/">
         <!--Optional:-->
         <tns:complextype0>
            <tns:value1>one</tns:value1>
            <!--Optional:-->
            <tns:value2>two</tns:value2>
            <!--Optional:-->
            <tns:value3>three</tns:value3>
            <!--Optional:-->
            <tns:value4>four</tns:value4>
            <!--Optional:-->
            <tns:value5>five</tns:value5>
         </tns:complextype0>
      </tns:method1>
   </soapenv:Body>
</soapenv:Envelope>

Web服务:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://test.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <tns:method1>
         <!--Optional:-->
         <complextype0>
            <value1>one</value1>
            <!--Optional:-->
            <value2>two</value2>
            <!--Optional:-->
            <value3>three</value3>
            <!--Optional:-->
            <value4>four</value4>
            <!--Optional:-->
            <value5>five</value5>
         </complextype0>
      </tns:method1>
   </soapenv:Body>
</soapenv:Envelope>

ComplexType0:

@WebService(serviceName = "NewService2TNS2")
public class NewService2TNS2 {


@WebMethod(operationName = "method1")    
public ComplexType1 method1(@WebParam(name = "complextype0") ComplexType0 complextype0) throws Throwable {
    ComplexType1 result = null;
    //processing data
    return result;
}

}

在寻找问题时,我遇到了一篇文章,他们说前缀和名称空间不应影响Web服务的运行。我不明白为什么数据不会出现在第一种情况下

0 个答案:

没有答案