SOAP Server in JAVA <-> SOAP Client in C# - java

I have a problem with a SOAP Server written in JAVA, the project is running as a windows service and not as a webserver (e.g. GLASSFISH).
So the problem is, everytime I make a request from a C# .NET client, the JAVA SOAP server is not able to parse the request. The called function gets a NULL value as input parameter.
The communictaion with JAVA clients, SoapUI, aso. works perfectly but the .NET (C#) clients are sending maleformed requests I think. Because the project is already existing and installed a lot of times, I can't develope it in C#.
I've read a lot of threads with similar problems, but I couldn't find any solution for my case.
I just wrote some simple test cases to show you the problem in a short way.
JAVA Code:
main.java
//...
Endpoint endpoint = Endpoint.create(new WS());
endpoint.publish("http://0.0.0.0:8081/test");
//...
WS.java
//...
#WebService(serviceName = "WS")
#SOAPBinding(style = SOAPBinding.Style.RPC)
public class WS {
#WebMethod(operationName = "echo")
public String echo(#WebParam(name = "val") String val) {
return val;
}
}
The WSDL:
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://webj/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://webj/" name="WS">
<types/>
<message name="echo">
<part name="val" type="xsd:string"/>
</message>
<message name="echoResponse">
<part name="return" type="xsd:string"/>
</message>
<portType name="WS">
<operation name="echo">
<input wsam:Action="http://webj/WS/echoRequest" message="tns:echo"/>
<output wsam:Action="http://webj/WS/echoResponse" message="tns:echoResponse"/>
</operation>
</portType>
<binding name="WSPortBinding" type="tns:WS">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
<operation name="echo">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal" namespace="http://webj/"/>
</input>
<output>
<soap:body use="literal" namespace="http://webj/"/>
</output>
</operation>
</binding>
<service name="WS">
<port name="WSPort" binding="tns:WSPortBinding">
<soap:address location="http://xxx:8081/test"/>
</port>
</service>
C# Request
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<s:Body>
<echo xmlns="http://webj/">
<val xmlns="http://webj/">TEST</val>
</echo>
</s:Body>
</s:Envelope>
JAVA Request
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:std="http://webj/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<std:echo>
<val>TEST</val>
</std:echo>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The problem seems to be the namespave of the parameter "val":
<echo xmlns="http://webj/">
<val xmlns="http://webj/">TEST</val>
</echo>
I've already tested this case in JAVA by adding a namespace to the parameter "val" manually and got the same problem. In C# I've tried with generated WebReferences and ServiceReferences.
(e.g. ServiceReference)
TestService.WSClient proxy = new TestService.WSClient();
String results = proxy.echo("TEST");
Can someone tell me how I can get the JAVA server compatible for .NET requests please?
Thanks for help!

Are you using Java JDK 1.8?
Because I don't think C# .NET is sending the namespace for the parameter, but it's sending an empty namespace like this:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<s:Body>
<echo xmlns="http://webj/">
<val xmlns="">TEST</val>
</echo>
</s:Body>
</s:Envelope>
Java JDK 1.8 contains a JAX-WS version with a bug. The empty namespaces of the requests of your C# client will be parsed completely wrong, just like your C# example above.
Try using the newsest version of >JAX-WS<.
>Here< you can find the description how to implement the libs.

As I see You have problem in namespaces, So when java parses it, finds no value and that's why you get null in Object values. Try to get the same XML structures from C#

Related

How to get simple javax.ws REST service url

Below is a toy example of a simple service using javax.ws. I want to get the service URL, callable from a web browser or curl.
This is the toy service code:
package packagename;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
#WebService
#Path("/service")
public class testserver
{
#GET
#Path("/test")
#WebMethod
public String test()
{
return "<html>Test text here</html>";
}
}
And this is the service deployer function:
package packagename;
import javax.xml.ws.Endpoint;
public class deploy
{
public static void main(String [] args)
{
String endpointURL = "http://localhost:7777/";
Endpoint.publish(endpointURL,new testserver());
}
}
I run the java file via bash without errors.
Shouldn't navigating to http://localhost:7777/service/test produce the text of the test() function? I am getting a Server not found error from my browser.
Below is the wsdl file at http://localhost:7777/?wsdl. Is the information I am looking for somewhere here? I have tried some urls by getting information from below (testserverService, etc) without success.
<!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e.
-->
<!-- Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e.
-->
<definitions targetNamespace="http://packagename/" name="testserverService">
<types>
<xsd:schema>
<xsd:import namespace="http://packagename/" schemaLocation="http://localhost:7777/?xsd=1"/>
</xsd:schema>
</types>
<message name="test">
<part name="parameters" element="tns:test"/>
</message>
<message name="testResponse">
<part name="parameters" element="tns:testResponse"/>
</message>
<portType name="testserver">
<operation name="test">
<input wsam:Action="http://packagename/testserver/testRequest" message="tns:test"/>
<output wsam:Action="http://packagename/testserver/testResponse" message="tns:testResponse"/>
</operation>
</portType>
<binding name="testserverPortBinding" type="tns:testserver">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="test">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="testserverService">
<port name="testserverPort" binding="tns:testserverPortBinding">
<soap:address location="http://localhost:7777/"/>
</port>
</service>
</definitions>
I am guessing the answer is very simple or I am making gross syntax errors in my code.
Can you help ?
You are mixing both SOAP and REST APIs, which is NOT correct. You can't use them together for the same endpoint.
javax.jws.* package (called as JAX-WS) represents SOAP API
javax.ws.rs.* package (called as JAX-RS) represents REST API
You need to understand the difference between SOAP & REST web services. You can look at here for more details on these concepts.
Assuming that you are looking for REST services implementation, in general, REST services are deployed into servers (like Tomcat, Jetty, Weblogic), but if you need to run them standalone look here

call third party web service using apache camel

I am new to camel
I am trying to call webservice using camel java dsl
from("cxf://http://darshan:8080/sampleWebService/SampleTestServicePort?wsdlURL=http://darshan:8080/sampleWebService/SampleTestServicePort?wsdl&serviceName={http://ws.test.com/}SampleTestServiceService&portName={http://ws.test.com/}SampleTestServicePort&dataFormat=MESSAGE")
following is my wsdl file:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.test.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.test.com/" name="SampleTestServiceService">
<types>
<xsd:schema>
<xsd:import namespace="http://ws.test.com/" schemaLocation="http://darshan:808O/sampleWebService/SampleTestServicePort?xsd=1"></xsd:import>
</xsd:schema>
</types>
<message name="sayHello">
<part name="parameters" element="tns:sayHello"></part>
</message>
<message name="sayHelloResponse">
<part name="parameters" element="tns:sayHelloResponse"></part>
</message>
<portType name="SampleTestServiceDelegate">
<operation name="sayHello">
<input message="tns:sayHello"></input>
<output message="tns:sayHelloResponse"></output>
</operation>
</portType>
<binding name="SampleTestServicePortBinding" type="tns:SampleTestServiceDelegate">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding>
<operation name="sayHello">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal"></soap:body>
</input>
<output>
<soap:body use="literal"></soap:body>
</output>
</operation>
</binding>
<service name="SampleTestServiceService">
<port name="SampleTestServicePort" binding="tns:SampleTestServicePortBinding">
<soap:address location="http://darshan:808O/sampleWebService/SampleTestServicePort"></soap:address>
</port>
</service>
</definitions>
That gives no error but also output is nothing.
Please suggest me what is wrong in my code.
Thanks in advance
When you use the Apache CXF Component as a from() what you are doing is you are hosting the webservice instead of accessing a third-party one.
To access a third-party service you need to use the to() form of the component. You need to do something like this:
<route>
<from uri="file:./myFileRequest?delay=1000&include=myRequest.xml">
<to uri="cxf://http://darshan:8080/sampleWebService/SampleTestServicePort?wsdlURL=http://darshan:8080/sampleWebService/SampleTestServicePort?wsdl&serviceName={http://ws.test.com/}SampleTestServiceService&portName={http://ws.test.com/}SampleTestServicePort&dataFormat=MESSAGE" />
...
</route>
Is this what you are looking for?
Define the cxf bean as below in the camel context
<cxf:cxfEndpoint
address="Service ENDPOINT"
endpointName="give wsdl:port#name here from wsdl"
id="any id" loggingFeatureEnabled="true"
serviceClass="your service class - it will be inside the stubs generated from WSDL"
serviceName="Service Name"
wsdlURL="WSDL path" xmlns:ws="namespace">
<cxf:properties>
<entry key="dataFormat" value="PAYLOAD"/>
</cxf:properties>
</cxf:cxfEndpoint>
then write the following in your route:
<to id="_to1" uri="cxf:bean:id Of the cxfEndpoint bean"/>

jax-ws :: wsimport and Apache CXF wsdl2java fail on a "normative" W3C WSDL specification example

I am trying to get wsimport or Apache CXF wsdl2java generate stubs for "Example 1" of the W3C WSDL 1.1 spec. (also copied verbatim at the end of the post).
The example appears to have a small typo, but even after replacing:
binding="tns:StockQuoteBinding
with
binding="tns:StockQuoteSoapBinding
both wsimport and wsdl2java still fail.
I've tried, the command line version (JAX-WS RI 2.2.4) and the Ant Task version (JAX-WS RI 2.2.8) of wsimport as well as the command line version of Apache CXF wsdl2java (2.7.6). They all seem to fail for the same reason more or less:
$ wsimport -version
JAX-WS RI 2.2.4-b01
$ wsimport -d src-auto-wsimport/ -p foo.client -Xnocompile specs/example1.wsdl
parsing WSDL...
[ERROR] Schema descriptor {http://example.com/stockquote.xsd}TradePriceRequest in message part "body" is not defined and could not be bound to Java. Perhaps the schema descriptor {http://example.com/stockquote.xsd}TradePriceRequest is not defined in the schema imported/included in the WSDL. You can either add such imports/includes or run wsimport and provide the schema location using -b switch.
line 31 of file:/home/brutus/jax-ws/wsdl/specs/example1.wsdl
From what I can see, the type it complains about (TradePriceRequest) is properly defined in the schema that's provided inside the WSDL file so I can't see why it fails to find it. (Apache CXF wsdl2java complains about the same type as well in a slightly different message)
Any ideas on what's wrong with this WSDL file?
example 1 WSDL (verbatim from the W3C WSDL 1.1 spec linked above)
NB: you need to change binding="tns:StockQuoteBinding to binding="tns:StockQuoteSoapBinding
<?xml version="1.0"?>
<definitions name="StockQuote"
targetNamespace="http://example.com/stockquote.wsdl"
xmlns:tns="http://example.com/stockquote.wsdl"
xmlns:xsd1="http://example.com/stockquote.xsd"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<schema targetNamespace="http://example.com/stockquote.xsd"
xmlns="http://www.w3.org/2000/10/XMLSchema">
<element name="TradePriceRequest">
<complexType>
<all>
<element name="tickerSymbol" type="string"/>
</all>
</complexType>
</element>
<element name="TradePrice">
<complexType>
<all>
<element name="price" type="float"/>
</all>
</complexType>
</element>
</schema>
</types>
<message name="GetLastTradePriceInput">
<part name="body" element="xsd1:TradePriceRequest"/>
</message>
<message name="GetLastTradePriceOutput">
<part name="body" element="xsd1:TradePrice"/>
</message>
<portType name="StockQuotePortType">
<operation name="GetLastTradePrice">
<input message="tns:GetLastTradePriceInput"/>
<output message="tns:GetLastTradePriceOutput"/>
</operation>
</portType>
<binding name="StockQuoteSoapBinding" type="tns:StockQuotePortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetLastTradePrice">
<soap:operation soapAction="http://example.com/GetLastTradePrice"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="StockQuoteService">
<documentation>My first service</documentation>
<port name="StockQuotePort" binding="tns:StockQuoteBinding">
<soap:address location="http://example.com/stockquote"/>
</port>
</service>
</definitions>

SoapUI not finding my web-service

So I've been struggling with web-services for a couple of days now, and It seemed that I finally had a breakthrough.
I followed this tutorial to the letter, and I have my web-service up and running. The only problem is, that I can't seem to test it via soapUI.
If I go to http://localhost:8084/soapwebservices It displays the data about my web-service, eg, the location of wsdl, and so on. Judging by that, the link is correct.
But when I try to send this request to it:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="soapwebservices.jdevelop.eu">
<soapenv:Header/>
<soapenv:Body>
<soap:calculateValues>
<value1>10</value1>
<value2>3.21</value2>
</soap:calculateValues>
</soapenv:Body>
</soapenv:Envelope>
I get a 404 error:
<head><title>Not Found (404)</title></head>
<body><h1>Not Found (404)</h1>
<b>Original request:</b> http://localhost:8084/soapwebservices<br><br>
<b>Not found request:</b> http://localhost:8084/soapwebservices</body>
Here is my WSDL:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns:ns1="soapwebservices.jdevelop.eu" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:ns="http://schemas.xmlsoap.org/soap/encoding/" name="SOAPWebServices" targetNamespace="soapwebservices.jdevelop.eu">
<types>
<xsd:schema>
<xsd:import namespace="soapwebservices.jdevelop.eu" schemaLocation="webservices.xsd"/>
</xsd:schema>
</types>
<message name="calculateValues">
<part name="calculateValues" element="ns1:calculateValues"/>
</message>
<message name="calculateValuesResponse">
<part name="calculateValuesResponse" element="ns1:calculateValuesResponse"/>
</message>
<portType name="SOAPWebServices">
<operation name="getCalculateValues">
<input message="ns1:calculateValues"/>
<output message="ns1:calculateValuesResponse"/>
</operation>
</portType>
<binding name="SOAPWebServicesPortBinding" type="ns1:SOAPWebServices">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getCalculateValues">
<soap:operation soapAction="urn:http://blog.jdevelop.eu/services/getCalculateValues"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="SOAPService">
<port name="WebServices" binding="ns1:SOAPWebServicesPortBinding">
<soap:address location="http://blog.jdevelop.eu:80/services"/>
</port>
</service>
</definitions>
What could be the problem here?
I am using Netbeans 6.0.1, Apache Tomcat 6.0 and Java SDK 1.7
Thanks!
Couple of observations:
In your SOAP message, the operation name you are sending is calculateValues (<soap:calculateValues>) whereas the operation name mentioned in the WSDL is getCalculateValues (<operation name="getCalculateValues">). This may be the reason behind 404 error as calculateValues operation is not defined.
I assume that you are not posting the SOAP message at the service URL mentioned in the WSDL (<soap:address location="http://blog.jdevelop.eu:80/services"/>).
Check the namespce in your endpoint class and the schema , both should be same

SoapUI MockServices returning html rather than xml response

Using the following sample WSDL file, I've generated a new project in SOAP UI (version 3.5), and created the example test suite, test case, and mock service.
WSDL
<definitions name="HelloService"
targetNamespace="http://www.examples.com/wsdl/HelloService.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.examples.com/wsdl/HelloService.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<message name="SayHelloRequest">
<part name="firstName" type="xsd:string"/>
</message>
<message name="SayHelloResponse">
<part name="greeting" type="xsd:string"/>
</message>
<portType name="Hello_PortType">
<operation name="sayHello">
<input message="tns:SayHelloRequest"/>
<output message="tns:SayHelloResponse"/>
</operation>
</portType>
<binding name="Hello_Binding" type="tns:Hello_PortType">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="sayHello">
<soap:operation soapAction="sayHello"/>
<input>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice"
use="encoded"/>
</input>
<output>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice"
use="encoded"/>
</output>
</operation>
</binding>
<service name="Hello_Service">
<documentation>WSDL File for HelloService</documentation>
<port binding="tns:Hello_Binding" name="Hello_Port">
<soap:address
location="http://www.examples.com/SayHello/"/>
</port>
</service>
</definitions>
I can start up the mock service and access via the browser, whereby I see a link to the wsdl and can view it.
However, by using the default generated soap request (as follows), it returns an html response (appears to be the web page) rather than the soap response I have configured.
REQUEST
POST http://localhost:8088/SayHello/ HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "sayHello"
User-Agent: Jakarta Commons-HttpClient/3.1
Host: localhost:8088
Content-Length: 467
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:examples:helloservice">
<soapenv:Header/>
<soapenv:Body>
<urn:sayHello soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<firstName xsi:type="xsd:string">James</firstName>
</urn:sayHello>
</soapenv:Body>
</soapenv:Envelope>
RESPONSE
HTTP/1.1 200 OK
Content-Type: text/html; charset=iso-8859-1
Transfer-Encoding: chunked
Server: Jetty(6.1.x)
<html><body><p>There are currently 1 running soapUI MockServices</p><ul><li>Hello_Binding MockService</li></ul></p></body></html>
I've configured a sample response as follows :
SAMPLE RESPONSE ON MOCK
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:examples:helloservice">
<soapenv:Header/>
<soapenv:Body>
<urn:sayHelloResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<greeting xsi:type="xsd:string">?</greeting>
</urn:sayHelloResponse>
</soapenv:Body>
</soapenv:Envelope>
Its configured as the default response, so I have no idea why it is not being returned.
Any suggestions? +1's to anything that helps me progress this.
Thanks
No service is started for the endpoint URL from your request: http://localhost:8088/SayHello/. The only started service is located at URL http://localhost:8088/mockHello_Binding as reported in the service response. SoapUI returns list of all started mock services in HTML page when a non-existed one is requested. Consider fixing endpoint address to resolve this issue.
I have hit the same problem using soap ui 5.4.0. It have happend beacuse the path of created mock service was incorrect.
If you click in the soap UI, on the created mock service - properties button on the bottom - you will see that your path looks like /mockBindingservice, it should say /.
To change it, double click on the created mock service, click stop service than settings button (located next to stop and start buttons).Change Path to / and double check host.
Save, start service. Should work now.
I know it is an old post, but hopefully it will help sombody looking for the anwser.
The Url you are hitting is incorrect. The MockService URL is created while you import the WSDL to SOAP with default port 8088.
Solution:
1)Create new Project
2)Import WSDL
3)Check Create Mockervice
4)Then you will SEE the URL where mockservice will run::-->mockSearchURL(for eg)
5)hit HTTP://{IP}:8088/mockSearchURL
DONE!!
i think is the name in Url and the name in request
Url : SayHello
Request : sayHello S and s
name should be matched
I has similar issue with BizTalk 2010 Send Port and Mock SOAPUI webservice.
I found out that the 2 URL er different
When I open this in IE..I see the HTML response.
http://localhost:8088/MockUpdateBasicHttp
When you opened this in IE I got a blank white screen which normally means success.
http://localhost:8088//MockUpdateBasicHttp
The correct URL is with a single '/' after port number.
http://localhost:8088/MockUpdateBasicHttp

Categories