Connecting Microsoft Dynamics GP10 web services - using Java
import java.net.URL;
import java.rmi.RemoteException;
import java.util.Hashtable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.Hashtable;
import java.util.Properties;
import org.apache.axis.SimpleTargetedChain;
import org.apache.axis.client.AxisClient;
import org.apache.axis.configuration.SimpleProvider;
import org.apache.axis.transport.http.CommonsHTTPSender;
import org.apache.log4j.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import com.microsoft.schemas.dynamics._2006._01.CompanyKey;
import com.microsoft.schemas.dynamics._2006._01.CurrencyType;
import com.microsoft.schemas.dynamics._2006._01.OrganizationKey;
import com.microsoft.schemas.dynamics.gp._2006._01.CurrencyKey;
import com.microsoft.schemas.dynamics.gp._2006._01.Dynamics_x0020_GPLocator;
import com.microsoft.schemas.dynamics.gp._2006._01.Dynamics_x0020_GPSoap;
import com.microsoft.schemas.dynamics.gp._2006._01.GetInventoriedItemByKey;
import com.microsoft.schemas.dynamics.gp._2006._01.Item;
import com.microsoft.schemas.dynamics.gp._2006._01.ItemCriteria;
import com.microsoft.schemas.dynamics.gp._2006._01.ItemKey;
import com.microsoft.schemas.dynamics.gp._2006._01.ItemSummary;
import com.microsoft.schemas.dynamics.gp._2006._01.LikeRestrictionOfString;
import com.microsoft.schemas.dynamics.gp._2006._01.Service;
import org.apache.axis.client.Stub;
public class GPConnect {
public static void main(String args[]) {
String endpoint = "http://xxxx:PORT/DynamicsGPWebServices/DynamicsGPService.asmx";
String username="domain\\xxxx";
String password = "xxxxx";
CompanyKey companyKey = null;
String currencyType = "Transactional";
String cultureName = "en-US";
String portNumber = "";
String roleKey = null;
Dynamics_x0020_GPSoap stub;
com.microsoft.schemas.dynamics.gp._2006._01.Dynamics_x0020_GPLocator locator = new Dynamics_x0020_GPLocator();
locator.setDynamics_x0020_GPSoap12EndpointAddress(endpoint);
com.microsoft.schemas.dynamics._2006._01.Context context= new com.microsoft.schemas.dynamics._2006._01.Context();
try {
stub = locator.getDynamics_x0020_GPSoap12();
((Stub)stub).setUsername(username);
((Stub)stub).setPassword(password);
Hashtable headers = new Hashtable();
headers.put("chunked", "false");
headers.put("Connection","keep-alive");
((Stub)stub)._setProperty("HTTP-Request-Headers", headers);
System.out.println("StubCreated");
ItemCriteria criteria= new ItemCriteria();
LikeRestrictionOfString itemClassId= new LikeRestrictionOfString();
itemClassId.setEqualValue("CATALOG");
criteria.setItemClassId(itemClassId)
context.setCultureName("en-US");
CurrencyType cuType = new CurrencyType("Transactional");
context.setCurrencyType(cuType);
companyKey = new CompanyKey();
companyKey.setId(-1);
OrganizationKey orgkey=(OrganizationKey)companyKey;
context.setOrganizationKey(orgkey);
ItemKey key = new ItemKey("128 SDRAM");
Item o = stub.getItemByKey(key , context);
System.out.println(o.getDescription());
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printmessage()
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printmessage()
}
}
}
NOTE : Using version AXIS 1.4 java client created and download the GP10.jar from the below link
"https://docs.google.com/open?id=0Byft-gwJbzuocFV6eUtxRExTY1NWUHQtZHQ2Tl9Sdw"
import java.rmi.RemoteException;
import java.util.Hashtable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.Hashtable;
import java.util.Properties;
import org.apache.axis.SimpleTargetedChain;
import org.apache.axis.client.AxisClient;
import org.apache.axis.configuration.SimpleProvider;
import org.apache.axis.transport.http.CommonsHTTPSender;
import org.apache.log4j.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import com.microsoft.schemas.dynamics._2006._01.CompanyKey;
import com.microsoft.schemas.dynamics._2006._01.CurrencyType;
import com.microsoft.schemas.dynamics._2006._01.OrganizationKey;
import com.microsoft.schemas.dynamics.gp._2006._01.CurrencyKey;
import com.microsoft.schemas.dynamics.gp._2006._01.Dynamics_x0020_GPLocator;
import com.microsoft.schemas.dynamics.gp._2006._01.Dynamics_x0020_GPSoap;
import com.microsoft.schemas.dynamics.gp._2006._01.GetInventoriedItemByKey;
import com.microsoft.schemas.dynamics.gp._2006._01.Item;
import com.microsoft.schemas.dynamics.gp._2006._01.ItemCriteria;
import com.microsoft.schemas.dynamics.gp._2006._01.ItemKey;
import com.microsoft.schemas.dynamics.gp._2006._01.ItemSummary;
import com.microsoft.schemas.dynamics.gp._2006._01.LikeRestrictionOfString;
import com.microsoft.schemas.dynamics.gp._2006._01.Service;
import org.apache.axis.client.Stub;
public class GPConnect {
public static void main(String args[]) {
String endpoint = "http://xxxx:PORT/DynamicsGPWebServices/DynamicsGPService.asmx";
String username="domain\\xxxx";
String password = "xxxxx";
CompanyKey companyKey = null;
String currencyType = "Transactional";
String cultureName = "en-US";
String portNumber = "";
String roleKey = null;
Dynamics_x0020_GPSoap stub;
com.microsoft.schemas.dynamics.gp._2006._01.Dynamics_x0020_GPLocator locator = new Dynamics_x0020_GPLocator();
locator.setDynamics_x0020_GPSoap12EndpointAddress(endpoint);
com.microsoft.schemas.dynamics._2006._01.Context context= new com.microsoft.schemas.dynamics._2006._01.Context();
try {
stub = locator.getDynamics_x0020_GPSoap12();
((Stub)stub).setUsername(username);
((Stub)stub).setPassword(password);
Hashtable
headers.put("chunked", "false");
headers.put("Connection","keep-alive");
((Stub)stub)._setProperty("HTTP-Request-Headers", headers);
System.out.println("StubCreated");
ItemCriteria criteria= new ItemCriteria();
LikeRestrictionOfString itemClassId= new LikeRestrictionOfString();
itemClassId.setEqualValue("CATALOG");
criteria.setItemClassId(itemClassId)
context.setCultureName("en-US");
CurrencyType cuType = new CurrencyType("Transactional");
context.setCurrencyType(cuType);
companyKey = new CompanyKey();
companyKey.setId(-1);
OrganizationKey orgkey=(OrganizationKey)companyKey;
context.setOrganizationKey(orgkey);
ItemKey key = new ItemKey("128 SDRAM");
Item o = stub.getItemByKey(key , context);
System.out.println(o.getDescription());
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printmessage()
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printmessage()
}
}
}
NOTE : Using version AXIS 1.4 java client created and download the GP10.jar from the below link
"https://docs.google.com/open?id=0Byft-gwJbzuocFV6eUtxRExTY1NWUHQtZHQ2Tl9Sdw"
Hi Sakthi Ram,
ReplyDeleteI am trying to connect MS Dynamics GP on premises from java, i have been trying this since last month, i have got confidence by seeing your post on the same, while running i have some runtime issues, please help me.
-------------------------------------------------------------------------------------------------------
StubCreated
AxisFault
faultCode: {http://www.w3.org/2003/05/soap-envelope}Server.userException
faultSubcode:
faultString: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Premature end of file.
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Premature end of file.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source)
---------------------------------------------------------------------------------------------------------------------------------------
Hi ,
DeleteThis is genericc error with the xml request sent to the MS Dynamics GP webservices.
Please check whether the environment for GP webservices has been setup successfully.
Also please refer the necessary jar files that are needed..
If possible, inbox your source code.
Thanks,
Hi SakthiRam,
ReplyDeleteI need to connect to GP 2013 using native endpoint. But I am not able to generate classes from native GP 2013 WSDL using wsdl2java as there are many conflicting declarations.
Do you know any fix for such issues or do you have classes generated for GP 2013.
Thanks
Shiv