Main BLOGGER
Google
WWW THIS BLOG
Wednesday, May 31, 2006
 
gt4 wsrf soap message

---Request CreateResource

 

<?xml version="1.0" encoding="UTF-8"?>

<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" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing">

 

<soapenv:Header>

  <wsa:MessageID soapenv:mustUnderstand="0">uuid:083d9e90-f0af-11da-9bca-e3cee5a2e991</wsa:MessageID>

  <wsa:To soapenv:mustUnderstand="0">http://128.226.182.124:8998/wsrf/services/examples/core/factory/MathFactoryService</wsa:To>

  <wsa:Action soapenv:mustUnderstand="0">http://www.globus.org/namespaces/examples/core/FactoryService/FactoryPortType/createResourceRequest</wsa:Action>

  <wsa:From soapenv:mustUnderstand="0"><wsa:Address>http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous</wsa:Address></wsa:From>

</soapenv:Header>

 

<soapenv:Body>

  <createResource xmlns="http://www.globus.org/namespaces/examples/core/FactoryService"/>

</soapenv:Body>

 

</soapenv:Envelope>

 

--- Response CreateResource

 

<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" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing">

 

<soapenv:Header>

  <wsa:MessageID soapenv:mustUnderstand="0">uuid:085df7d0-f0af-11da-ad34-d5b17adc3a4f</wsa:MessageID>

  <wsa:To soapenv:mustUnderstand="0">http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous</wsa:To>

  <wsa:Action soapenv:mustUnderstand="0">http://www.globus.org/namespaces/examples/core/FactoryService/FactoryPortType/createResourceResponse</wsa:Action>

  <wsa:From soapenv:mustUnderstand="0"><wsa:Address>http://128.226.182.124:8998/wsrf/services/examples/core/factory/MathFactoryService</wsa:Address></wsa:From>

  <wsa:RelatesTo RelationshipType="wsa:Reply" soapenv:mustUnderstand="0">uuid:083d9e90-f0af-11da-9bca-e3cee5a2e991</wsa:RelatesTo></soapenv:Header>

 

<soapenv:Body>

  <createResourceResponse xmlns="http://www.globus.org/namespaces/examples/core/FactoryService">

     <wsa:EndpointReference>

         <wsa:Address>http://128.226.182.124:8998/wsrf/services/examples/core/factory/MathService</wsa:Address>

         <wsa:ReferenceProperties>

            <ns1:MathResourceKey xmlns:ns1="http://www.globus.org/namespaces/examples/core/MathService_instance">15619471</ns1:MathResourceKey>

         </wsa:ReferenceProperties>

         <wsa:ReferenceParameters/>

    </wsa:EndpointReference>

  </createResourceResponse>

</soapenv:Body></soapenv:Envelope>

 

----add request

<?xml version="1.0" encoding="UTF-8"?>

<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" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing">

 

<soapenv:Header>

   <wsa:MessageID soapenv:mustUnderstand="0">uuid:08e13190-f0af-11da-9bca-e3cee5a2e991</wsa:MessageID>

   <wsa:To soapenv:mustUnderstand="0">

       http://128.226.182.124:8998/wsrf/services/examples/core/factory/MathService

   </wsa:To>

   <wsa:Action soapenv:mustUnderstand="0">

       http://www.globus.org/namespaces/examples/core/MathService_instance/MathPortType/addRequest

   </wsa:Action>

   <wsa:From soapenv:mustUnderstand="0">

     <wsa:Address>http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous</wsa:Address>

   </wsa:From>

   <ns1:MathResourceKey soapenv:mustUnderstand="0" xmlns:ns1=

         "http://www.globus.org/namespaces/examples/core/MathService_instance">

     15619471

   </ns1:MathResourceKey>

</soapenv:Header>

 

<soapenv:Body>

  <add xmlns="http://www.globus.org/namespaces/examples/core/MathService_instance">10</add>

</soapenv:Body>

 

</soapenv:Envelope>

 

---add response

<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" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing">

<soapenv:Header>

<wsa:MessageID soapenv:mustUnderstand="0">uuid:08e48cf0-f0af-11da-ad34-d5b17adc3a4f</wsa:MessageID>

<wsa:To soapenv:mustUnderstand="0">http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous

</wsa:To>

<wsa:Action soapenv:mustUnderstand="0">http://www.globus.org/namespaces/examples/core/MathService_instance/MathPortType/addResponse

</wsa:Action>

<wsa:From soapenv:mustUnderstand="0" xmlns:ns1="http://www.globus.org/namespaces/examples/core/MathService_instance">

<wsa:Address>http://128.226.182.124:8998/wsrf/services/examples/core/factory/MathService</wsa:Address>

<wsa:ReferenceProperties>

<ns1:MathResourceKey soapenv:mustUnderstand="0" xmlns:ns1="http://www.globus.org/namespaces/examples/core/MathService_instance" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">15619471</ns1:MathResourceKey>

</wsa:ReferenceProperties>

</wsa:From>

<wsa:RelatesTo RelationshipType="wsa:Reply" soapenv:mustUnderstand="0">uuid:08e13190-f0af-11da-9bca-e3cee5a2e991

</wsa:RelatesTo>

 

</soapenv:Header>

 

<soapenv:Body><addResponse xmlns="http://www.globus.org/namespaces/examples/core/MathService_instance"/>

</soapenv:Body></soapenv:Envelope>


Tuesday, May 30, 2006
 
Java: using system property

1. use java –D option to define system property

   <!-- define the "run-xclient" target -->

   <target name="runX" depends="xClient">

      <java classname="xclient.Client" fork="true">

        <jvmarg value="-DcontainerHome=${project-home}"/>

        <classpath refid="classpath"/>

        <classpath>

            <pathelement location="${project-home}/classes"/>

        </classpath>

      </java>

   </target>

 

2. in the code, use System.getProperty()

          String home = System.getProperty("containerHome", "/home/pliu/");

 

In this way, we can use different build.properties file and switch smoothly between windows and linux

 

<?xml version="1.0"?>

 

<project default="build">

 

   <property file="build.properties"/>

 

 

 


 
JAX-RPC: soap header

Tried to add SOAP header into the SOAP message in JAX-RPC,

A lot of links showed how to achieve that, but they do not work.

http://www-128.ibm.com/developerworks/webservices/library/ws-tipjax1.html

http://users.skynet.be/pascalbotte/rcx-ws-doc/jaxrpchandler.htm

http://java.boot.by/wsd-guide/ch04s07.html

 

Finally, found this link (quite old though)

http://www.myfaq.com.cn/A/2003-10-08/142177.html

 

And add a element in the config.xml to solve this problem

 

<?xml version="1.0" encoding="UTF-8"?>

<configuration

    xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">

   <wsdl location="./wsdl/mcwsWSRFService.wsdl" packageName="mcwsClient">

      <handlerChains>

         <chain runAt="client">

            <handler className="handler.ResourceIDHandler">

              <property name="name" value="Resource ID  handler"/>

            </handler>

         </chain>

     </handlerChains>  

   </wsdl>

</configuration> 

 

 

 

 


Wednesday, May 24, 2006
 
java jni tutorial
A good one, simple and works well.

http://public.cabit.wpcarey.asu.edu/janjua/java/jni/


Two methods to load DLL
1. System.loadLibrary(String)
2. System.load(String)
http://www.inonit.com/cygwin/jni/helloWorld/load.html

Sunday, May 21, 2006
 
WSRF.net Howto
1. install WSRFdotNet
2. rebuild the solution by VS2005
3. go to ${WSRFdotNet}Scripts\SqlExpress, run "setup.bat" to setup database
4. run NUnit to test the newly installation

trouble shoot
1. can not see WSRF PAT tool bar
rebuild add-in
trick: have to exit from VS2005 and then manually copied the files
from C:\WSRFdotNet\Src\Tools\WSRFServiceAddin\bin\Debug
to C:\WSRFdotNet\Bin

2. WSRF PAT is not invoked
a. Have to remove the Service.asmx.generated.cs file from the project,
b. then modify Service.asmx to remove the UVa.xxx prefix, for example
previous: Class="UVa.GCG.Generated.RingService.Service"
after: Class="RingService.Service"
c. make some code change in your service.cs

3. In order to use WSRF.NET,
it seems we can only create website in local IIS instead of local file system


4. create send in container
a. copy the reference.cs from UTest webreference directory
b. change the name space of reference.cs
c. change this.url = UTest.xxx to this.url = "" (two places)
d. remember to run upDll.bat

5. xclient
a. changes in mcwsWSRFPortType.wsdl,
-- tns:Object to xsd:anyType
-- remove Object element
-- change name from Object to anyType
b. add soap:address location="http://localhost/mcws"/
in port element in file mcwsService.wsdl
In order to avoid type name conflict, we'd better avoid to use
xxxRequest, xxxResponse class name in WSRF.NET, else
wscompile will get trouble

Tuesday, May 16, 2006
 
some thoughts about dynamic deployment

I am improving my implementation for dynamic deployment via X# code.

 

Previously, for each incoming X# code, the container will create a separate module (in .JAR or .DLL) by translating X# to Java/C# at first, then invoking the Java compiler or C# compiler. When the user calls the deployed services, which in turn will trigger the newly generated modules, we will face the same situation like DLL hell. Simply introducing version control on DLLs is not enough. If we treat the incoming X# as patches, we may have DLLs with different version co-existing in the same system.

 

This leads to an interesting situation. Those DLLs may provide the same functionality but in different version. And the policy to use those DLLs varies. The application may need function A in DLL v1.1, function B in DLL v1.2. Or the newest version will always be used.  One possible approach could utilize the chained responsibility pattern. In this approach, the older DLL will forward the invocation to newer DLL until the version criteria are met or the newest version is used. The obvious drawback of this approach is that, in the long run, the chain will become so long to be broken easily. And it will also compromise the performance. Another approach could employ a version control coordinator to fetch the matched DLLs into memory and invoke DLLs through this coordinator. The extra effort should be put to avoid name confliction among DLLs with same functionality but with different version.  And the prerequisite of this approach is the need of Meta data for DLLs.

 

The root of trouble in above approaches is to treat DLLs as the atomic deployment unit. If we could use some facility to re-assemble DLLs with different version into a target DLL meeting all kinds of version criteria, the entire headache will go. Since in our framework, the deployment unit is in X# code instead of DLLs, we could achieve this goal easily. First, the re-assembly will be as simple as maintain a DOM tree. We can cut or attach new node in the tree to generate the target Tree. And from this tree, we will generate the final executable DLLs. During runtime execution, there will be no extra overhead. Second, there is no need for extra Meta data management because the XML based X# code includes all the Meta information within itself. On the other hand, it provides a better way than CVS to maintain code versioning because tree-based X# has finer granularity than line-base CVS.

 

In a nutshell, the point is to do versioning control on X# code instead of DLLs and postpone the generation of DLL until the merged X# code is ready.

 

I will apply this approach to APEA-MCWS project. The user will provide callback to override the previous implementation and our container will re-assemble the X# code via XML DOM tree manipulation, and then dynamically generate the DLL (only one copy in the system!). The version control management is transferred from DLL to X#. And we can borrow the idea of differential serialization/de-serialization to improve the efficiency of dynamic X# deployment. Instead of sending the XML snippet, which could be very huge, we can just describe the operation for the differential part. For example, we could say “Delete Node xxx à Add Node yyy à Change Node zzz “etc.  The result framework will support dynamic deployment of web service in a novel way.

 

I believe this part of work could be a separate paper named “language supported web service dynamic deployment”. What do you think?

 


Monday, May 15, 2006
 
.NET container issues
1. Sandboxing code dynamically

Quoted from http://www.dotnetthis.com/Articles/DynamicSandboxing.htm

I have been getting questions from people about how to make a piece of managed code execute in a security restricted environment, or how to "sandbox" it. Some people are trying to use stack walk modifiers (such as Deny()) to do it, which does not work for this purpose. Other people are trying to modify the machine security policy (which when done correctly works) or put an application in question on a network share and run it from there (which also works and gives the application LocalIntranet permissions, if your policy is default). There is however a way to sandbox a piece of code dynamically, by creating an appdomain, setting its security policy and loading an assembly there.


2. .NET remoting in appDomain
Quoted from http://www.codeproject.com/csharp/processactivator2.asp

This article is a follow-up to my previous article entitled: "Simple but potentially useful example of .NET Remoting". In my earlier article, I expounded on basic codes necessary to startup a .NET remoting project. The example code of that article used Server Activated Remote Objects. In this article, we shift our attention to Client Activated Remote Objects which are different from and are often much more useful than server activated ones.

 
FSM and state pattern
UML Tutorial: Finite State Machines
http://www.objectmentor.com/resources/articles/umlfsm.pdf

State Pattern in C++ Applications
http://www.codeproject.com/cpp/statepattern3.asp?df=100&forumid=2614&exp=0&select=1450830

 
C++ WS container and WSRF
Deploying C++ Grid Services: Options and Performance
http://www.cs.duke.edu/~anda/cps296.5/final_projects/PaperWS.pdf

Writing Web Services in C/C++ using Globus Toolkit V 4.0 (GT4)

http://www.jwork.net/GT4WSC/

State and Events for Web Services: A Comparison of Five WS


Globus C core
1. WSRF
http://www.globus.org/toolkit/docs/4.0/common/cwscore/C-GT4-WSRF-Design.pdf
2. C container
http://www.globus.org/toolkit/docs/4.0/common/cwscore/C-GT4-WS-Design.pdf


Wednesday, May 10, 2006
 
c++ wrapper for C array

http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=207&rl=1

 

 

template <class T, int _size> struct array_wrapper
{
 //typedef names used in STL algorithms and containers
 typedef T value_type;
 typedef T* iterator;
 typedef const T * const_iterator;
 typedef T& reference;
 typedef const T& const_reference;
 
T v[_size]; //the actual array
// member functions of STL containers
operator T* () {return v;}
reference operator[] (size_t idx) {return v[idx];}
const_reference operator[] (size_t idx) const {return v[idx];}
 
iterator begin() {return v;}
const_iterator begin() const {return v;}
 
iterator end() {return v+_size;}
const_iterator end() const {return v+_size;}
 
size_t size() const {return _size;}
};

 

 

void func(int *, int sz); // C function 
//wrap an array of 20 int's initializing its members to 0
array_wrapper<int, 20> arr={0}; 
func(arr, arr.size()); //using T* conversion operator

 


 
gsoap: from wsdl to .h

echo gsoap client stub

cd stub

rm *

rem use the typemap.dat

rem xsd__anyType    = | xsd__anyType

rem mcws    = "http://www.cs.binghamton.edu/mcws"

cp ..\typemap.dat .

rem use dom++ for xsd__anyType

cp ..\dom++.h .

wsdl2h -s -c -o gsoap_mcws.h ..\..\wsdl\mcws.wsdl

echo #import "dom++.h" > temp.h

cat gsoap_mcws.h >> temp.h

rem remove the gsoapopt line

sh -c "sed 's_\/\/gsoapopt cw__' < temp.h > mcwsSoap.h"

soapcpp2 -d..\stub mcwsSoap.h

cd ..


Monday, May 08, 2006
 
java code to list jar files in a directory

    private URL[] listJar(String dir)

    {

      URL[] urls = null;

      String suffix=".jar";

      int total=0;

      try{

        File f = new File(dir);

        if (!f.exists() || !f.isDirectory())

        {

           System.out.println ( dir+" does NOT exist" );

           return null;

        }

        String path = f.getPath();

        String[] files = f.list();

        for (int i =0; i < files.length; i++)

        {

            File f2 = new File(path, files[i]);

            if (f2.isFile())

            {

               if ((files[i].lastIndexOf(suffix))==(files[i].length()-suffix.length()))

               {

                  System.out.println(files[i]);

                  total++;

               }

            }

        }

        urls = new URL[total+1];

        String fileSeparator = System.getProperty("file.separator");

        int index=1;

        for (int i =0; i < files.length; i++)

        {

            File f2 = new File(path, files[i]);

            if (f2.isFile())

            {

               if ((files[i].lastIndexOf(suffix))==(files[i].length()-suffix.length()))

               {

                  File f3=new File(path+fileSeparator+files[i]);

                  urls[index]=f3.toURL();

                  index++;

               }

            }

        }

 

        System.out.println("total:"+(new Integer(total)).toString());      

        return urls;

      }catch(Exception e)

      {

        System.out.println ( "Exception:" + e.toString());

        return null;

      }

    }


Saturday, May 06, 2006
 
Interoperability for Document-Based Web Services (ASP.NET)

How to manipulate xsd:anyType in asp.net web service, JWSDP, and gSOAP

This is the first part about ASP.NET

Two good papers are at

http://java.sun.com/developer/technicalArticles/xml/jaxrpcpatterns/index.html

http://java.sun.com/developer/technicalArticles/xml/jaxrpcpatterns2/

Overall, there are five approaches to use document-based web services.

* Using XML in the SOAP Body

* Using a String in the SOAP Body

* Using base64Encoded or raw bytes in the SOAP body

* Using the xsd:any Element in WSDL

* Using the xsd:anyType in WSDL

We will use xsd:anyType for interoperability. And the purpose is to have a state management web service.

It is like a web service based hash table. By the key (xsd:string), client can put/get the value (xsd:anyType) afterwards.

The web service will maintain the stateful information for client. The xml serialization class could be created on the fly.

The assumption is contract first approach, that is, we have a WSDL definition beforehand.

<!-- put state -->

<xsd:element name="putStateRequest">

<xsd:complexType>

<xsd:sequence>

<xsd:element type="xsd:string" name="key" />

<xsd:element type="xsd:anyType" name="value" />

</xsd:sequence>

</xsd:complexType>

</xsd:element>

<xsd:element name="putStateResponse">

<xsd:complexType />

</xsd:element>

<!-- get state -->

<xsd:element name="getStateRequest">

<xsd:complexType>

<xsd:sequence>

<xsd:element type="xsd:string" name="key" />

</xsd:sequence>

</xsd:complexType>

</xsd:element>

ASP.net web service

It will use System.Object to map xsd:anyType.

  1. use xmlserializer to do the serialization and deserialization. The only overhead is to declare a normal class.
  2. create a class to implement IXmlSerializable to take over the control of read/write xml. Resource 5 gave a thorough example to control everything by overriding xmlwriter.

The arbitrary class is defined as

public class myObject

{

public int i;

public float f;

public string s;

};

The code example for approach 1 is:

The helper function is from Resources 3.

public static string XmlString(object o)

{

StringWriter writer = null;

try

{

XmlSerializer formatter = new XmlSerializer(o.GetType());

writer = new StringWriter();

formatter.Serialize(writer, o);

return writer.ToString();

}

finally

{

if (writer != null) writer.Close();

}

}

public static object XmlString(string xml, Type type)

{

StringReader reader = null;

try

{

XmlSerializer formatter = new XmlSerializer(type);

reader = new StringReader(xml);

return formatter.Deserialize(reader);

}

finally

{

if (reader != null) reader.Close();

}

}

Testing code

myObject m=new myObject();

m.i = 4;

m.f = 1.3F;

m.s = "hello";

string xmlStr = XmlString(m);

putReq.value = (object)xmlStr;

service.putState(putReq);

getResp = service.getState(getReq);

myObject ret = (myObject)XmlString((string)getResp.getStateResult, m.GetType());

Console.WriteLine(ret.i);

Console.WriteLine(ret.f);

Console.WriteLine(ret.s);

The code example for approach 2 is:

public class myObject2 : IXmlSerializable

{

public int i;

public float f;

public string s;

public XmlSchema GetSchema()

{

return null;

}

public void WriteXml(XmlWriter w)

{

w.WriteStartElement("i");

w.WriteString(i.ToString());

w.WriteEndElement();

w.WriteStartElement("f");

w.WriteString(f.ToString());

w.WriteEndElement();

w.WriteStartElement("s");

w.WriteString(s);

w.WriteEndElement();

}

public void ReadXml(XmlReader r)

{

string str;

r.Read();

r.ReadStartElement("i");

str = r.ReadString();

i = Convert.ToInt32(str);

r.ReadEndElement();

r.ReadStartElement("f");

str = r.ReadString();

f = Convert.ToSingle(str);

r.ReadEndElement();

r.ReadStartElement("s");

s = r.ReadString();

r.ReadEndElement();

}

}

Testing code

myObject2 m2 = new myObject2();

m2.i = 5;

m2.f = 3.4F;

m2.s = "world";

putReq.value = (string)XmlString(m2);

service.putState(putReq);

getResp = service.getState(getReq);

myObject2 ret2 = (myObject2)XmlString((string)getResp.getStateResult, m2.GetType());

Console.WriteLine(ret2.i);

Console.WriteLine(ret2.f);

Console.WriteLine(ret2.s);

Resources

1. Trouble shooting for xmlserializer

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp

2. Tutorial of xmlserializer

http://www.topxml.com/xmlserializer/default.asp

3. serialization/de-serialization helper functions in C#

http://lewismoten.blogspot.com/2005/02/demonstrating-serialization-in-net.html

4. Customize XML Serialization using IXmlSerializable

http://wwww.developerfusion.com/show/4639/

5. .NET XML and SOAP serialization samples

http://www.codeproject.com/soap/Serialization_Samples.asp

http://aspzone.com/blogs/john/articles/167.aspx


Monday, May 01, 2006
 
trouble shooting for firewall and gsoap

1. change the soap bind to    

  m = soap_bind(&soap, 0 , m_port, BACKLOG);

DO NOT use

m = soap_bind(&soap, “localhost” , m_port, BACKLOG);

 

2. in windows, [start] >>> [control panel] >>> [windows Firewall] >>> [Exceptions] >>> [Add Port…]

 

Give a name and the port for mcws gsoap service.

 

 



Powered by Blogger

Google
WWW THIS BLOG