Announcement Announcement Module
Collapse
No announcement yet.
Spring WS Client - Invocation Issue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring WS Client - Invocation Issue

    Hi,

    I am having hard time getting to run a sample app using Sping WS for invoking a public Web service. I keep getting SOAP Action Header Exception or xml not being well formed exception. Here is my client

    import java.io.StringReader;
    import javax.xml.transform.stream.StreamResult;
    import javax.xml.transform.stream.StreamSource;

    import org.springframework.ws.WebServiceMessageFactory;
    import org.springframework.ws.client.core.WebServiceTempl ate;
    import org.springframework.ws.client.core.support.WebServ iceGatewaySupport;
    import org.springframework.ws.transport.WebServiceMessage Sender;

    public class WebServiceClient extends WebServiceGatewaySupport{

    private static final String uszipInput="<GetInfoByZIP><USZip>60148</USZip></GetInfoByZIP>";
    // private static final String uszipInput="<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> <soap:Body> <GetInfoByZIP xmlns=\"http://www.webserviceX.NET\"> <USZip>string</USZip> </GetInfoByZIP> </soap:Body></soap:Envelope>";


    // send to the configured default URI
    public void simpleSendAndReceive() {

    StreamSource source = new StreamSource(new StringReader(uszipInput));
    StreamResult result = new StreamResult(System.out);
    getWebServiceTemplate().sendSourceAndReceiveToResu lt(source, result);
    }


    }


    Here is my applicationContext.xml


    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

    <beans default-autowire="byName">
    <bean id="webServiceClient" class="WebServiceClient">
    <property name="defaultUri" value="http://www.webservicex.net/uszip.asmx/GetInfoByZIP"/>
    </bean>
    </beans>


    And I am trying to invoke the GetInfoByZip operation on the web server. I am able to run this using the JaxRpcPortProxyFactoryBean approach.

    Thank you for your help !

  • #2
    The reference documentation contains a section about setting the SOAPAction header on the client, see http://static.springframework.org/sp...t.html#d0e2758

    Comment


    • #3
      Arjen-

      Thanks for the reference. It did help me overcome the SOAPActionHeader problem
      I changed my client now


      String uszipInput="<?xml version = \"1.0\" encoding = \"utf-8\"?><GetInfoByZIP><USZip>60148</USZip></GetInfoByZIP>";
      source = new StreamSource(new StringReader(uszipInput));
      StreamResult result = new StreamResult(System.out);
      webServiceTemplate.sendSourceAndReceiveToResult(
      source,
      new SoapActionCallback("http://www.webserviceX.NET/GetInfoByZIP"),
      result);


      And I also modified my applicationContext.xml to include a messageSender

      <bean id="webServiceTemplate"
      class="org.springframework.ws.client.core.WebServi ceTemplate">
      <property name="defaultUri"
      value="http://www.webservicex.net/uszip.asmx" />
      <property name="messageSender">
      <bean
      class="org.springframework.ws.transport.http.HttpU rlConnectionMessageSender" />
      </property>

      </bean>


      But now, I am able to make the webservice invocation but somehow the input gets lost and webservice does not return any thing.

      Comment


      • #4
        Are you sure it doesn't return something? You can use a tool like tcpmon to verify what is sent over the wire. See https://tcpmon.dev.java.net/

        Comment


        • #5
          Hi Arjen,

          I used tcpmon to monitor webservice request and looks like the request is going fine and the HTTP response is also seems to OK but just that the results are not what expect when that web service is invoked directly from the browser.
          For instance, here are the request/response as seen from tcpmon

          POST /uszip.asmx HTTP/1.1
          Accept-Encoding: gzip
          SOAPAction: "http://www.webserviceX.NET/GetInfoByZIP"
          Content-Type: text/xml
          Cache-Control: no-cache
          Pragma: no-cache
          User-Agent: Java/1.5.0_13
          Host: localhost:8080
          Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
          Connection: keep-alive
          Content-Length: 272

          <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><GetInfoByZIP><USZip>60148 </USZip></GetInfoByZIP></soapenv:Body></soapenv:Envelope>




          HTTP/1.1 200 OK
          Date: Sun, 03 Feb 2008 16:26:34 GMT
          Server: Microsoft-IIS/6.0
          X-Powered-By: ASP.NET
          X-AspNet-Version: 1.1.4322
          Cache-Control: private, max-age=0
          Content-Type: text/xml; charset=utf-8
          Content-Length: 305

          <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetInfoByZIPResponse xmlns="http://www.webserviceX.NET" /></soap:Body></soap:Envelope>



          Expected reponse is

          <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetInfoByZIPResponse xmlns="http://www.webserviceX.NET" />
          <?xml version="1.0" encoding="utf-8" ?>
          <NewDataSet>
          <Table>
          <CITY>Lombard</CITY>
          <STATE>IL</STATE>
          <ZIP>60148</ZIP>
          <AREA_CODE>630</AREA_CODE>
          <TIME_ZONE>C</TIME_ZONE>
          </Table>
          </NewDataSet>

          </soap:Body></soap:Envelope>

          Comment


          • #6
            Hi Coolj,

            I tried the Web Service call u were trying..I see the mistake ur doing is not using the Namespace in your XML Request.

            ie. instead of doing this..

            String uszipInput="<?xml version = \"1.0\" encoding = \"utf-8\"?><GetInfoByZIP><USZip>60148</USZip></GetInfoByZIP>";

            U need to be doing the below..and it works..If u try the above...u are getting empty XML..so ur not seeing anything..

            String uszipInput="<?xml version = \"1.0\" encoding = \"utf-8\"?><GetInfoByZIP xmlns="http://www.webserviceX.NET">><USZip>60148</USZip></GetInfoByZIP>";

            If u look at the Soap Request in the URL..u will see the namespace is being expected as part of the request.

            Comment


            • #7
              Hi Arjen,

              I have a question for u...I am trying to use a web service which is close to the Web Service that is being talked about in this chain but there is small difference..

              The request Soap XML is like this...

              <?xml version="1.0" encoding="utf-8"?>
              <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
              <soap:Body>
              <GetInfoByState xmlns="http://www.webserviceX.NET/">
              <USState>string</USState>
              </GetInfoByState>
              </soap:Body>
              </soap:Envelope>


              If you observe, the namespace has additional slash ie.. xmlns="http://www.webserviceX.NET/"> When I try such a web service call, I am running into WebServiceTransform Exception..

              How do I handle such scenarios in the WebService Client Call???

              Appreciate your help in advance.

              Thanks,
              DP

              Comment

              Working...
              X