简体   繁体   English

使用Java消费SOAP API

[英]Consume SOAP API in Java

I have been searching everywhere on how to consume a SOAP API built in C# / ASP.NET in Java. 我到处都在搜索如何使用Java中以C#/ ASP.NET构建的SOAP API。 I am currently using Spring / Spring Web for my projects and I wish to use a SOAP API with Spring-WS to no luck. 我目前在我的项目中使用Spring / Spring Web,并且希望在Spring-WS中使用SOAP API。

The envelopes are generated incorrectly and when I send a request it simply states "500 internal server error" 信封生成不正确,当我发送请求时,它仅指出“ 500内部服务器错误”

The namespaces at the top where it has SOAP-ENV:Envelope are incorrect and when using the WSDL in SoapUI the data is presented as soap:Envelope so I am not sure if this is an issue with how it is being marshalled into an XML string. 顶部具有SOAP-ENV:Envelope的名称空间不正确,并且在SoapUI中使用WSDL时,数据显示为soap:Envelope,因此我不确定这是如何将其编组为XML字符串的问题。

I am sending this: 我发送此:

    TestRequest test = WS_CLIENT_FACTORY.createTestRequest();
    test.setData(1);

    JAXBElement<TestRequest> req = WS_CLIENT_FACTORY.createTestRequest(test);

    getWebServiceTemplate().marshalSendAndReceive(req);

This sends the request, but outputting the XML data that is actually being sent is incorrectly put together and the server doesn't seem to like it. 这会发送请求,但是输出实际发送的XML数据时会错误地放在一起,服务器似乎不喜欢它。

I am not sure if a C# / ASP SOAP API Server is handled differently to the way Java does things? 我不确定C#/ ASP SOAP API服务器的处理方式是否不同于Java的处理方式? If anyone can enlighten me on this please do help me! 如果有人可以启发我,请帮助我!

I went back to using the basic JAX-WS as part of Java and used the "wsimport" tool. 我回到使用基本的JAX-WS作为Java的一部分,并使用“ wsimport”工具。 It turns out when I did it before, it was missing off the SOAP Headers so you can actually generate the requests with the additional headers included with the following command. 原来,当我这样做时,它缺少SOAP标头,因此您实际上可以使用以下命令中包含的其他标头来生成请求。

wsimport -keep -Xnocompile -XadditionalHeaders -extension

Although this is not using Spring's implementation of consuming a SOAP API, it seems to work a lot better. 尽管这没有使用Spring的使用SOAP API的实现,但它似乎工作得更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM