试图找出为什么这两个SOAP请求中的一个不起作用(java.lang.IllegalArgumentException)



我有一个正在运行的 JAX-WS Web 服务,它已经有一些工作端点。现在我遇到了以下问题:

我在这里有两个不同的 SOAP 请求,我不明白为什么第一个有效,而第二个不起作用。

请求中唯一明显的区别是,第一个在<Envelope>标记中指定命名空间,而第二个在调用方法<getMoldDataHistory>时指定它。

SOAP 请求 1 - 不工作(命名空间在方法调用中指定(

<s:Envelope
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
>
<s:Body
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
<getMoldDataHistory
xmlns="http://history.production.soap.webservices.product.company.at/">
<machineId>92623-15853588</machineId>
<start>0</start>
<end>0</end>
</getMoldDataHistory>
</s:Body>
</s:Envelope>

SOAP 请求 2 - 工作(命名空间在<Envelope>标记中指定(

<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:his="http://history.production.soap.webservices.product.company.at/">
<soapenv:Header/>
<soapenv:Body>
<his:getMoldDataHistory>
<machineId>92623-15853588</machineId>
<start>0</start>
<end>0</end>
</his:getMoldDataHistory>
</soapenv:Body>
</soapenv:Envelope>

我在发出第一个(不起作用(请求时收到的 SOAP 错误消息。

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
<faultcode>S:Server</faultcode>
<faultstring>java.lang.IllegalArgumentException</faultstring>
</S:Fault>
</S:Body>
</S:Envelope>

收到第一个 SOAP 请求时从服务器引发的异常的堆栈跟踪。

java.lang.IllegalArgumentException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.xml.internal.ws.api.server.MethodUtil.invoke(Unknown Source)
at com.sun.xml.internal.ws.api.server.InstanceResolver$1.invoke(Unknown Source)
at com.sun.xml.internal.ws.server.InvokerTube$2.invoke(Unknown Source)
at com.sun.xml.internal.ws.server.sei.EndpointMethodHandler.invoke(Unknown Source)
at com.sun.xml.internal.ws.server.sei.SEIInvokerTube.processRequest(Unknown Source)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Unknown Source)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Unknown Source)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Unknown Source)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Unknown Source)
at com.sun.xml.internal.ws.server.WSEndpointImpl$2.process(Unknown Source)
at com.sun.xml.internal.ws.transport.http.HttpAdapter$HttpToolkit.handle(Unknown Source)
at com.sun.xml.internal.ws.transport.http.HttpAdapter.handle(Unknown Source)
at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handleExchange(Unknown Source)
at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handle(Unknown Source)
at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
at sun.net.httpserver.AuthFilter.doFilter(Unknown Source)
at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(Unknown Source)
at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
at sun.net.httpserver.ServerImpl$Exchange.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

所以我基本上试图弄清楚为什么第一个请求不起作用,尽管它是一个有效的 SOAP 请求。我需要在我的服务器上配置什么才能允许此类请求吗?

编辑:

在做了更多的测试后,我发现如果我调用的方法有 0 个参数,命名空间声明的位置并不重要。一旦需要参数,它就会停止工作。

编辑2:

现在我在这里偶然发现了这个线程.我有同样的问题。发出请求的 C# 客户端不使用方法 TAG 中的命名空间。添加后它可以工作。

我仍然如何告诉 JAX-WS 来处理这个问题。

不起作用:

<getMoldDataHistory xmlns="http://history.production.soap.webservices.product.company.at/">

工程:

<his:getMoldDataHistory xmlns:his="http://history.production.soap.webservices.product.company.at/">

使用绑定到命名空间的前缀时,如

<his:getMoldDataHistory xmlns:his="http://history.production.soap.webservices.product.company.at/">
<machineId>92623-15853588</machineId>
<start>0</start>
<end>0</end>
</his:getMoldDataHistory>

然后,仅将元素getMoldDataHistory放入指定的命名空间中。原因是语法xmlns:his="..."只声明前缀。然后,必须在要位于指定命名空间中的所有元素上使用此方法。在此代码段中,唯一的元素是getMoldDataHistory

使用xmlns="..."语法,如

<getMoldDataHistory xmlns="http://history.production.soap.webservices.product.company.at/">
<machineId>92623-15853588</machineId>
<start>0</start>
<end>0</end>
</getMoldDataHistory>

不仅声明命名空间,还将关联的元素和所有子元素放入此命名空间中。

结论:这两个 XML 代码段在语义上并不等效。

如果有"扩展元素名称"语法之类的东西,那么这些 XML 片段将看起来像......

第一个:

<{http://history.production.soap.webservices.product.company.at/}getMoldDataHistory>
<{}machineId>92623-15853588</{}machineId>
<{}start>0</{}start>
<{}end>0</{}end>
</{http://history.production.soap.webservices.product.company.at/}getMoldDataHistory>

第二个:

<{http://history.production.soap.webservices.product.company.at/}getMoldDataHistory>
<{http://history.production.soap.webservices.product.company.at/}machineId>92623-15853588</{http://history.production.soap.webservices.product.company.at/}machineId>
<{http://history.production.soap.webservices.product.company.at/}start>0</{http://history.production.soap.webservices.product.company.at/}start>
<{http://history.production.soap.webservices.product.company.at/}end>0<{/http://history.production.soap.webservices.product.company.at/}end>
</{http://history.production.soap.webservices.product.company.at/}getMoldDataHistory>

最新更新