gSOAP C++ client connectivity issue RRS feed

  • Question

  • Our requirement is to access Dynamics CRM metadata/data from Linux machine. The apporach we are using is to generate C++ stubs from WSDL and use the stubs to get data:

    Example: Get timestamp from MetadataService.

    1) Import WSDL
    2) Generate Stubs:
    wsdl2h -o MetadataService.h MetadataService.Wsdl
    soapcpp2 -i -C -x -ID:\gsoap-2.8\gsoap\import MetadataService.h

    After that, the following code is written to connect to the Metadata Service. 

    C++ code (returns 401: Unauthorized)

    MetadataServiceSoapProxy service;
    service.userid = "msdynamics\\sysadmin";
    service.passwd = "tempBG@2";
    service.soap_endpoint = "";

    // Authentication token
    ct2__CrmAuthenticationToken* authToken = soap_new_ct2__CrmAuthenticationToken(&service, -1);
    authToken->AuthenticationType = 0;
    authToken->OrganizationName = new string("msdynamics");
    authToken->CallerId = "79B65D97-75D3-DF11-9373-005056A87867";

    // Caller origin token
    ct2__CallerOriginToken* coToken = soap_new_ct2__CallerOriginToken(&service, -1);
    service.soap_header(coToken, authToken);

    // Retrieve the timestamp.
    ws2__RetrieveTimestampRequest* tsReq = soap_new_ws2__RetrieveTimestampRequest(&service, -1);
    _ws2__Execute* request = soap_new__ws2__Execute(&service, -1);
    request->Request  = tsReq;

    _ws2__ExecuteResponse response;
    int ret = service.Execute(request, &response);
    if(SOAP_OK == ret)
    ws2__RetrieveTimestampResponse* resp = (ws2__RetrieveTimestampResponse*)response.Response;

    return ret;

    C#.net equivalent code, which works fine.

      // Create an authentication token.
                CrmAuthenticationToken token = new CrmAuthenticationToken();
        token.OrganizationName = "msdynamics";

                // You can use enums.cs from the SDK\Helpers folder to get the enumeration for AD Authentication.
        token.AuthenticationType = 0;

                token.CallerId = new Guid("79B65D97-75D3-DF11-9373-005056A87867");

                // Create the metadata Web service.
                MetadataService service = new MetadataService();
                service.Url = "";
                service.CrmAuthenticationTokenValue = token;            
                service.Credentials = new System.Net.NetworkCredential("sysadmin", "tempBG@2", "msdynamics");

                // Retrieve the timestamp.
                RetrieveTimestampRequest request = new RetrieveTimestampRequest();
                RetrieveTimestampResponse response = (RetrieveTimestampResponse)service.Execute(request);

    Is setting userid, passwd equivalent to setting to service credentials. if not, how to pass credentials using gSOAP generated C++ code?

    Monday, November 15, 2010 3:08 PM


  • Does gSOAP support NTLM authentication?  If not, that is likely your problem.  The method of passing credentials looks pretty much like it would in .NET, but if gSOAP only supports Basic HTTP authentication, you will not be able to successfully authenticate against CRM.

    --pogo (pat)
    Monday, November 15, 2010 11:29 PM