使用SOAP1.2服务时出现Content-Type错误

时间:2018-09-30 02:51:44

标签: web-services soap content-type soap1.2

我在使用SOAP1.2服务时遇到麻烦。我收到此错误:

com.sun.xml.internal.ws.server.UnsupportedMediaException:Unsupported 
Content-Type: text/xml Supported ones are: [application/soap+xml] 
at 
com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode
(StreamSOAPCodec.java:220)

以下是WSDL详细信息和生成的Java客户端:

<wsdl:operation name="redeem">
<soap12:operation 
       soapAction="http://org.comp.PartnerService
       /PartnerConnectorResponder/redeem" style="document" />

-----------------------------------------------------------------------
Client (WSImport Generated)
-----------------------------------------------------------------------

/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.2.8
* Generated source version: 2.2
* 
*/

@WebServiceClient(name = "PartnerService", targetNamespace = 
"http://tempuri.org/", wsdlLocation = "/jaxws/PartnerService_1.wsdl")
public class PartnerService extends Service
{
   @WebEndpoint(name = "WSHttpBinding_PartnerConnectorResponder")
   public PartnerConnectorResponder getConnectorResponder() {
       return super.getPort(
              new QName("http://tempuri.org/", 
              "PartnerConnectorResponder"), 
              ,PartnerConnectorResponder.class);
   }
}

-----------------------------------------------------------------------
Invocation: [Pseudo code]
-----------------------------------------------------------------------
fun redeem() {
   var soapClient:PartnerConnectorResponder = getConnectorResponder()
   var bindingProvider:BindingProvider=(soapClient asBindingProvider)

   bindingProvider.getRequestContext().put("Content-Type", "application/soap+xml")

   //Also tried lower 't' in type but no luck
   //bindingProvider.getRequestContext().put("Content-type", "application/soap+xml")

   bindingProvider.redeem();
}

代码以某种方式设置了SOAP 1.1的默认内容类型(text / xml)。即使我手动设置了内容类型,它仍然会失败,并显示相同的错误。

我真的很感激,因为我已经呆了一个星期了。谢谢。

1 个答案:

答案 0 :(得分:0)

通过将以下属性添加到SOAP客户端来解决此问题: AddressingFeature(true)