Simon Fell > Its just code > More on Indigo

Wednesday, May 18, 2005

Using Kirill's tips, I was finally able to get a simple Indigo client up and running

  1. svcutil /uxs /tm /config:client.exe.config enterprise.wsdl
  2. modify the generated code to add the Position attributes to the login_RequestMessage class, as Kirill details.
  3. This is going over HTTP because I still haven't been able to get HTTPS work (tried a few different things with a variety of errors), so only use it with test logins!
  4. Change the generated config file to change the endpoint address to http from https
  5. Change the generated config file to increase the max message size
  6. Compile and run this code
SoapProxy proxy = new SoapProxy("Soap");
login_RequestMessage loginMsg = new login_RequestMessage();
loginMsg.username = "[your_login]";
loginMsg.password = "[your_password]";

login_ResponseMessage lr = proxy.login(loginMsg);
LoginResult res = lr.result;
Console.WriteLine(res.serverUrl);
Console.WriteLine(res.sessionId);

Binding bind = proxy.Endpoint.Binding;
proxy = new SoapProxy(new EndpointAddress(res.serverUrl.Replace("https:","http:")), bind);

query_RequestMessage qrm = new query_RequestMessage();
qrm.SessionHeader = new SessionHeader();
qrm.SessionHeader.sessionId = res.sessionId;
qrm.queryString = "Select Id, Name from Account";
qrm.QueryOptions = new QueryOptions();
qrm.QueryOptions.batchSize = 10;
qrm.QueryOptions.batchSizeSpecified = true;

query_ResponseMessage rm = proxy.query(qrm);		
Console.WriteLine(rm.result.size);		
foreach (Account o in rm.result.records) {
	Console.WriteLine("{0} {1}", o.Id, o.Name);
}		

And off you go, having to manually manage the header values between each call and the type message programming model makes it feel really cumbersome, I hope at least the operation_RequestMessage objects will get constructors that allow you to set all the values in one go.

I was also surprised to find that the resulting serialization to be unusual, seems more verbose that most of today's tools, I also noticed that it doesn't send up a Http User-Agent header.

<s:Envelope
    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Header>
      <h:QueryOptions
          xmlns="urn:enterprise.soap.sforce.com"
          xmlns:h="urn:enterprise.soap.sforce.com"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:xsd="http://www.w3.org/2001/XMLSchema">
          <batchSize>10</batchSize>
        </h:QueryOptions>
       <h:SessionHeader
          xmlns="urn:enterprise.soap.sforce.com"
          xmlns:h="urn:enterprise.soap.sforce.com">
         <sessionId>[mySessionId]</sessionId>
        </h:SessionHeader>
     </s:Header>
   <s:Body>
      <query
          xmlns="urn:enterprise.soap.sforce.com"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:xsd="http://www.w3.org/2001/XMLSchema">
         <queryString>Select Id, Name from Account</queryString>
        </query>
     </s:Body>
  </s:Envelope>