Connecting Microsoft Dynamics GP10 web services – using Java


Use the  below java code to connect MS dynamics GP10


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()
}
}
}

 


Thanks for reading this article!! please leave your comments and suggestion about this article.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s