XSUL Dynamic Invoker Problem with .NET

"Andre P." <[email protected]> Tue, 31 Oct 2006 14:52:19 -0300
Newsgroups gmane.comp.apache.webservices.wsif.user
Message-ID <[email protected]>
Hello list!

I got the latest xsul library(2.7.9), and everything is working fine when
dynamic invoking some web services (deployed in axis, phpnusoap, websphere),
except for the Document/Literal Wrapped .NET Web Services.

With the logging utility enabled, I can see that the SOAP envelope is not
sending the parameters correctly when the service is in .NET!

My args are http://localhost/GetPrice/Service.asmx?WSDL  getPrice  keyboard

The envelope is incorrect (in bold), the value of "item" is not included
(should be <item>keyboard</item> isn't it?). I'm also attaching the .wsdl of
the .NET service, and the .java of xsul dynamic invoker (without the
selftest and stuff).

Thanks in advance for any help!

Best regards,

Andre


############### ENVELOPE ################
<?xml version='1.0' encoding='utf-8'?>
<S:Envelope xmlns:xsd=' http://www.w3.org/2001/XMLSchema'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:wsa=' http://www.w3.org/2005/08/addressing'
xmlns:wsp='http://schemas.xmlsoap.org/ws/2002/12/policy
' xmlns:S='http://schemas.xmlsoap.org/soap/envelope/'
<http://schemas.xmlsoap.org/soap/envelope/%27>>
  <S:Header>
     <wsa:To>http://localhost/GetPrice/Service.asmx</wsa:To>
     <wsa:Action> http://tempuri.org//ServiceSoap/getPrice</wsa:Action>
  </S:Header>
  <S:Body>
     <n1:item xmlns:n1=' http://tempuri.org/' />
  </S:Body>
</S:Envelope>



############### WSDL ################
  <?xml version="1.0" encoding="utf-8" ?>
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<wsdl:definitions xmlns:soap
="*http://schemas.xmlsoap.org/wsdl/soap/*"xmlns:tm="
*http://microsoft.com/wsdl/mime/textMatching/*" xmlns:soapenc=" *
http://schemas.xmlsoap.org/soap/encoding/*" xmlns:mime="*
http://schemas.xmlsoap.org/wsdl/mime/*" xmlns:tns="*
http://tempuri.org/*"xmlns:s
="*http://www.w3.org/2001/XMLSchema*" xmlns:soap12 ="*
http://schemas.xmlsoap.org/wsdl/soap12/*" xmlns:http="*
http://schemas.xmlsoap.org/wsdl/http/*" targetNamespace="*http://tempuri.org/
*" xmlns:wsdl="*http://schemas.xmlsoap.org/wsdl/*">
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<wsdl:types>
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<s:schema elementFormDefault ="*qualified*" targetNamespace="*
http://tempuri.org/*">
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<s:element name ="*item*">
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<s:complexType>
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<s:sequence>
   <s:element minOccurs="*0* " maxOccurs="*1*" name="*item*" type="*s:string
*" />
  </s:sequence>
  </s:complexType>
  </s:element>
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<s:element name ="*getPriceResponse*">
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<s:complexType>
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<s:sequence>
   <s:element minOccurs="*1* " maxOccurs="*1*" name="*getPriceResult*" type
="*s:double*" />
  </s:sequence>
  </s:complexType>
  </s:element>
  </s:schema>
  </wsdl:types>
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<wsdl:message name ="*getPriceSoapIn*">
   <wsdl:part name="*parameters* " element="*tns:item*" />
  </wsdl:message>
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<wsdl:message name ="*getPriceSoapOut*">
   <wsdl:part name="*parameters* " element="*tns:getPriceResponse*" />
  </wsdl:message>
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<wsdl:portType name ="*ServiceSoap*">
 +<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<wsdl:operation name ="*getPrice*">
   <wsdl:input message="*tns:getPriceSoapIn* " />
   <wsdl:output message="*tns:getPriceSoapOut* " />
  </wsdl:operation>
  </wsdl:portType>
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<wsdl:binding name ="*ServiceSoap*" type="*tns:ServiceSoap*">
   <soap:binding transport="* http://schemas.xmlsoap.org/soap/http*" />
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<wsdl:operation name ="*getPrice*">
   <soap:operation soapAction="* http://tempuri.org/getPrice*" style="*
document*" />
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<wsdl:input>
   <soap:body use="*literal* " />
  </wsdl:input>
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<wsdl:output>
   <soap:body use="*literal* " />
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<wsdl:binding name ="*ServiceSoap12*" type="*tns:ServiceSoap*">
   <soap12:binding transport="* http://schemas.xmlsoap.org/soap/http*" />
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<wsdl:operation name ="*getPrice*">
   <soap12:operation soapAction="* http://tempuri.org/getPrice*" style="*
document*" />
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<wsdl:input>
   <soap12:body use="*literal* " />
  </wsdl:input>
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<wsdl:output>
   <soap12:body use="*literal* " />
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<wsdl:service name ="*Service*">
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<wsdl:port name ="*ServiceSoap*" binding="*tns:ServiceSoap*">
   <soap:address location="* http://localhost/GetPrice/Service.asmx*" />
  </wsdl:port>
 -<?ik=93c1ed3437&view=cv&search=sent&th=10e9e61abe62dd2b&ww=1152&lvp=-1&cvp=3&qt=&zx=il0ytp-gacyq4#10e9e61abe62dd2b_>
<wsdl:port name ="*ServiceSoap12*" binding="*tns:ServiceSoap12*">
   <soap12:address location="* http://localhost/GetPrice/Service.asmx*" />
  </wsdl:port>
  </wsdl:service>
  </wsdl:definitions>






######################## JAVA #########################

import java.io.File ;
import java.net.URI;
import java.util.Iterator;
import java.util.List;
import javax.xml.namespace.QName;
import org.xmlpull.v1.builder.XmlElement;
import org.xmlpull.v1.builder.XmlInfosetBuilder;
import xsul.MLogger;
import xsul.XmlConstants;
import xsul.wsdl.WsdlBindingOperation;
import xsul.wsdl.WsdlDefinitions;
import xsul.wsdl.WsdlMessage;
import xsul.wsdl.WsdlPortTypeOperation;
import xsul.wsdl.WsdlResolver ;
import xsul.wsif.WSIFException;
import xsul.wsif.WSIFMessage;
import xsul.wsif.WSIFOperation;
import xsul.wsif.WSIFPort;
import xsul.wsif.WSIFService;
import xsul.wsif.WSIFServiceFactory;
import xsul.wsif.impl.WSIFMessageElement ;
import xsul.wsif.spi.WSIFProviderManager;

public class XsulDynamicInvoker {
    private final static MLogger logger = MLogger.getLogger();
    private final static XmlInfosetBuilder builder = XmlConstants.BUILDER ;

    private static void usage(String errMsg) {
        System.err.println("Usage: {WSDL URL} {operation name} [parameters
...]");
    }

    public static void main(String[] args) throws Exception
    {
        System.err.println("Starting "+XsulDynamicInvoker.class.getName());
        WSIFProviderManager.getInstance().addProvider( new
xsul.wsif_xsul_soap_http.Provider() );
        runClient(args);
    }

    private static void runClient(String[] args) throws Exception {
        URI base = ((new File(".")).toURI());

        if(args.length < 2) {
            usage("at least two argument required");
        }

        String wsdlLoc = args[0];

        String opName = args[1];
        String portName = null;
        if(opName.charAt(0) == '{') {
            int pos = opName.indexOf('}');
            portName = opName.substring(1, pos);
            opName = opName.substring(pos+1);
        }

        System.err.println("invoking operation '"+opName+"' using WSDL from
"+wsdlLoc);
        //log everything!
        MLogger.setCmdNames(":ALL");
        WsdlDefinitions def = WsdlResolver.getInstance().loadWsdl(base, new
URI(wsdlLoc));

        WSIFServiceFactory wsf = WSIFServiceFactory.newInstance();
        WSIFService serv = wsf.getService(def);

        WSIFPort port = serv.getPort(portName);

        WSIFOperation op = port.createOperation(opName);
        WSIFMessage in = op.createInputMessage();

        WsdlBindingOperation bindingOp =  op.getBindingOperation();
        WsdlPortTypeOperation portTypeOp = bindingOp.lookupOperation();
        WsdlMessage inputMsg = portTypeOp.getInput().lookupMessage();
        Iterator partNames = in.partNames().iterator();

        int count = 2;
        while(partNames.hasNext()) {
            //determine type of argument
            String partName = (String) partNames.next ();
//partNames.get(i-2);
            if(count < args.length) {
                String partValue = args[count];
                System.err.println(partName+"="+partValue);
                in.setObjectPart (partName, partValue);
            } else {
                // will try to do some defaulting
                QName type = ((WSIFMessageElement)in).getPartType(partName);

                String localPart = type.getLocalPart();
                if("string".equals(localPart)) {
                    in.setObjectPart(partName, "foo string");
                    System.err.println("defaulting
"+partName+"="+in.getObjectPart(partName));
                } else if("anyURI".equals(localPart)) {
                    in.setObjectPart(partName,
"gsiftp://rainier//tmp/foo.txt");
                    System.err.println("defaulting
"+partName+"="+in.getObjectPart(partName));
                } else if("URIArrayType".equals(localPart)) {
                    XmlElement arrayEl = builder.newFragment(partName);

arrayEl.addElement("value").addChild("gsiftp://rainier//tmp/foo.txt");

                     in.setObjectPart(partName, arrayEl);
                    System.err.println("defaulting
"+partName+"="+in.getObjectPart(partName));
                }
            }
            ++count;
        }

        if(op.isRequestResponseOperation()) {
            WSIFMessage out = op.createOutputMessage();
            WSIFMessage fault = op.createFaultMessage();
            boolean succes = op.executeRequestResponseOperation(in, out,
fault);
            if(succes) {
                System.out.println("received response "+out);
            } else {
                System.err.println("received fault "+fault);
            }
        } else {
            op.executeInputOnlyOperation(in);
            System.out.println("input only message was sent successfully");
        }
    }
}