Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

  • Problem with the webservices - smartgwt

    Hi

    I am trying to invoke webservices from smartgwt api,
    Code:
    package com.example.myproject.client;
    
    import java.util.LinkedHashMap;
    import java.util.Map;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.data.WSDLLoadCallback;
    import com.smartgwt.client.data.WebService;
    import com.smartgwt.client.data.WebServiceCallback;
    import com.smartgwt.client.data.XMLTools;
    import com.smartgwt.client.util.Page;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.ButtonItem;
    import com.smartgwt.client.widgets.form.fields.TextItem;
    import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
    import com.smartgwt.client.widgets.form.fields.events.ClickHandler;
    import com.smartgwt.client.widgets.layout.HLayout;
    import com.google.gwt.core.client.JavaScriptObject;
    import com.smartgwt.client.rpc.RPCManager;
    import com.smartgwt.client.rpc.RPCResponse;
    
    public class SmartGWTWebservices implements EntryPoint {
          private WebService myservice;
          public void onModuleLoad(){
    
                HLayout hl = new HLayout();
                MyForm mi=new MyForm();
                hl.addMember(mi);
                final MyForm form=new MyForm();
                ButtonItem bi = new ButtonItem("ClickMe");
                bi.addClickHandler(new ClickHandler() {
                      public void onClick(ClickEvent event) {
                        SC.say("Clicked the button....");
                        form.callService();
                      }
                    });
                form.setItems(bi);
          hl.addMember(form);
          //RPCManager.setUseHttpProxy(true);
    
                XMLTools.loadWSDL("https://somehost/HelloService/remoting/helloService?wsdl", new WSDLLoadCallback() {
                      public void execute(WebService webService) {
                        myservice = webService;
                      }
                    });
                hl.setWidth(Page.getWidth());
    hl.draw();
                
                
          }
          
          class MyForm extends DynamicForm{
                
                
                public void callService(){
                      if(myservice==null){
                            SC.say("Still Processing Try again......");
                      }else{
                            Map inputData = new LinkedHashMap();
                            inputData.put("Name", "Pavan");
                            //RPCManager.setUseHttpProxy(true);
                            myservice.callOperation("sayHello",inputData,null, new WebServiceCallback() {
    
                                public void execute(Object[] data, JavaScriptObject xmlDoc, RPCResponse rpcResponse,
                                    JavaScriptObject wsRequest) {
                                    
                                    
                                  SC.say("Hi, " + ((JavaScriptObject)data[0]));
                                  SC.say("Hello " + new TextItem((JavaScriptObject)data[0]).getValueAsString());
                                  
                                }
                              });
                      }
                      
                }
                
                
          }
          
          
          
    }
    This is the code i was written to invoke a method named sayHello, I have supposed to get a message "Hello <some name>" but it is always getting null printed

    can you please help me where i am doing the mistake

    Thanks
    Pavan

  • #2
    I am getting the JavaScriptObject, i am conveting it to a map with the help of JSOHelper and getting the value of the key which is a tag in soap xml response. Please direct me if i am doing in wrong way

    Thanks
    Pavan

    Comment


    • #3
      What about:

      XMLTools.selectString(data, "//xpath/tagname")

      instead of

      ((JavaScriptObject)data[0])

      Change //xpath/tagname to something that exist in you reply.

      Comment


      • #4
        Guys,


        I need to send a nested data to my webservice. The typical Webservice example using the LinkedMap for the outgoing request is great for a service that takes one single input or multiple (below). In this case USZip. Does anyone have an example of how to fill in a linkedMap for a complex type.

        The example is simple but I want an example on a more complex soap body with numerous required input data and maybe a complex types or two.
        data.put("USZip", getValueAsString("ZipCode"));


        ZipForm extends DynamicForm {
        public void callService() {
        if (zipCodeService == null) {
        SC.say("Please try again in a moment - still loading web service descriptor");
        } else {
        setValue("City", "Loading...");
        Map data = new LinkedHashMap();
        data.put("USZip", getValueAsString("ZipCode"));
        zipCodeService.callOperation("GetInfoByZIP", data, "//CITY", new WebServiceCallback() {

        public void execute(Object[] data, JavaScriptObject xmlDoc, RPCResponse rpcResponse,
        JavaScriptObject wsRequest) {
        ZipForm.this.setValue("City", (String) data[0]);
        }
        });
        }
        }
        }

        Comment


        • #5
          The best single discussion is the doc for useFlatFields.

          If you're filling out a complex set of elements you can either arrange a set of nested Maps and Lists that corresponds the XML structure if the data were serialized by DataSource.xmlSerialize(), or, with useFlatFields:true, you can provide the data "flattened" and have SmartGWT automatically fill in same-named elements, generating intervening XML structure as needed. This latter approach is more robust across possible changes to your WSDL message format.

          Comment


          • #6
            Thanks for the quick response.
            I actually tried that yesterday but for some reason, its not working. I feel like I am not setting it it at the right place.

            I tried to set it using the asRequest. I guess my question is how does the following code correlate with the actual request.
            XmlNamespaces aXmlNamespaces = new XmlNamespaces();
            aXmlNamespaces.addNamespace("ws", "http://dude.host.com/testService");
            WSRequest aWSRequest = new WSRequest();
            aWSRequest.setXmlNamespaces(aXmlNamespaces);
            aWSRequest.setUseFlatFields(true);

            Here the SOAP code. I am trying to set SystemID below.


            <soapenv:Body>
            <dev:GetZipCode>
            <ZipCode>dafadf</ZipCode>
            <!--Optional:-->
            <serviceContext>
            <!--Optional:-->
            <dat:SystemID>?</dat:SystemID>
            <!--Optional:-->
            <dat:TouchID>?</dat:TouchID>
            <!--Optional:-->
            </serviceContext>
            </dev:GetZipCode>
            </soapenv:Body>

            Originally posted by Isomorphic
            The best single discussion is the doc for useFlatFields.

            If you're filling out a complex set of elements you can either arrange a set of nested Maps and Lists that corresponds the XML structure if the data were serialized by DataSource.xmlSerialize(), or, with useFlatFields:true, you can provide the data "flattened" and have SmartGWT automatically fill in same-named elements, generating intervening XML structure as needed. This latter approach is more robust across possible changes to your WSDL message format.

            Comment


            • #7
              Not clear on your question about how the code correlates with the request, but, if you were trying to set SystemID with useFlatFields:true, you'd just use map.put("SystemID", value) and provide that map as the wsRequest's data.

              Comment


              • #8
                It appears the forum did not keep the formatting.

                It works when I am setting ZipCode only but once I try sending two values, it 's not sending the second.

                So I can do
                Map data = new LinkedHashMap();
                data.put("USZip", getValueAsString("ZipCode"))


                but when I do
                Map data = new LinkedHashMap();
                data.put("USZip", getValueAsString("ZipCode"))
                data.put("SystemID", getValueAsString("USSystemID"))

                It sends out only SystemID and does not send ZipCode. SO I thought the issue was the useFlatFields but apparently not.


                map.

                <soapenv:Body>
                <dev:GetZipCode>
                <ZipCode>dafadf</ZipCode>
                <!--Optional:-->
                <serviceContext>
                <dat:SystemID>?</dat:SystemID>
                <dat:TouchID>?</dat:TouchID>
                <!--Optional:-->
                </serviceContext>
                </dev:GetZipCode>
                </soapenv:Body>

                Originally posted by Isomorphic
                Not clear on your question about how the code correlates with the request, but, if you were trying to set SystemID with useFlatFields:true, you'd just use map.put("SystemID", value) and provide that map as the wsRequest's data.
                Last edited by Osa; 20th Nov 2011, 15:49.

                Comment


                • #9
                  The tag is SystemID not USSystemID.

                  Comment


                  • #10
                    Yes, that was a result of me trying to translate the code without using my actual code. I still have the same issue. Basically, you are saying that even with the complex xml structure that I have, it should find the systemID and send that value. I must be doing something wrong in my code somewhere else. I spend some time to re-write and let you know what I find out. T
                    Originally posted by Isomorphic
                    The tag is SystemID not USSystemID.

                    Comment


                    • #11
                      Yes, if the tag name matches, useFlatFields will cause the data to be populated at whatever level of nesting.

                      But aside from getting the tag name wrong, there are a few other possibilities such your WSDL not actually containing schema for that area of the message at all. For example, if the schema for the message just says "any tags are allowed here", then no system would know where you intended your SystemID value to go.

                      Comment


                      • #12
                        I think you are right. Also, I discovered that the quote should be dat:SystemID because the SOAP call in SOAP UI actually has <dat:SystemID>?</dat:SystemID>.

                        I think you are right about the Schema, I will contact our webservice developer.


                        Originally posted by Isomorphic
                        Yes, if the tag name matches, useFlatFields will cause the data to be populated at whatever level of nesting.

                        But aside from getting the tag name wrong, there are a few other possibilities such your WSDL not actually containing schema for that area of the message at all. For example, if the schema for the message just says "any tags are allowed here", then no system would know where you intended your SystemID value to go.

                        Comment


                        • #13
                          Leave the namespace qualifier out ("dat:") - we fill that in automatically as it's implied by the schema (assuming the schema completely specifies the message).

                          Comment


                          • #14
                            Thank you. This was really helpful.

                            Originally posted by Isomorphic
                            Leave the namespace qualifier out ("dat:") - we fill that in automatically as it's implied by the schema (assuming the schema completely specifies the message).

                            Comment


                            • #15
                              Hello Isomorphic

                              I am still having issues with this. We looked at the WSDL and it does have the schema - its in an XSD. So SystemID is a field in an object called serviceContext which is in a different namespace and also defined in a different XSD. I am wondering if I need to load that XSD to make this work?

                              Originally posted by Osa
                              Thank you. This was really helpful.

                              Comment

                              Working...
                              X