Tuesday, June 29, 2010

Connecting MS CRM 4.0 using Java webservices

Continue from connecting with MS CRM 3.0

The following is the sample code to connect MSCRM 4.0

String password = "password";

String username = "user";
String OrganizationName = "orgname";  //Whats Org Name

String endpointURL = "http://server:port/MSCrmServices/2007/CrmService.asmx"

CrmAuthenticationToken token = new CrmAuthenticationToken();
token.setCallerId("00000000-0000-0000-0000-000000000000");
token.setOrganizationName(OrganizationName);
//token.setAuthenticationType(0);

CrmServiceSoapStub bindingStub = (CrmServiceSoapStub) new CrmServiceLocator().getCrmServiceSoap(new URL(endpointURL));
bindingStub.setHeader("http://schemas.microsoft.com/crm/2007/WebServices",
"CrmAuthenticationToken", token);

bindingStub.setUsername(username);
bindingStub.setPassword(password);

WhoAmIRequest whoRequest = new WhoAmIRequest();
WhoAmIResponse whoResp = (WhoAmIResponse)bindingStub.execute(whoRequest);
String userid = whoResp.getUserId();
System.out.println("userid = "+userid );

I will provide the sample code for connecting MS CRM Services for all types of deployment

NSString constants in Objective C

Easiest way:
// constants.h
#define MY_CONSTANT @"my_constant"
 
Better way:
// constants.h
extern NSString * const MY_CONSTANT;
// constants.m
NSString * const MY_CONSTANT = @"const value";

There is also one thing to mention. If you need a non global constant, you should use static keyword.
Example

// in constants.m file
static NSString * const MY_CONSTANT = @"const value";

The following are some interesting article.

Java Developer’s Guide to String Constants in Objective-C

Correct way of defining constants in Objective-C