|  | Home | Documentation | Code Example 3: Publishing a WSDL and service on XMethods updated by Robert van Engelen |

Code Example 3: Publishing a WSDL and service on XMethods

This example shows you how to publish a Web service. In this case, the example template code obtains an authorization token, saves the tModel with the WSDL URL in the server, and saves the business service information in the server.

#include "pubH.h"
const char *server = "https://uddi.xmethods.net/publish";
const char *userid = "..."; // user ID to access UDDI server
const char *passwd = "..."; // password to access UDDI server
int main(int argc, char **argv)
{
// Create a gSOAP context
struct soap *soap = soap_new();
// Setup SSL context (optional) to verify server's credentials
if (soap_ssl_client_context(soap, SOAP_SSL_DEFAULT, NULL, NULL, "cacerts.pem", NULL, NULL))
{
soap_print_fault(soap, stderr);
exit(1);
}
// Step 1: Get an authorization token from the UDDI server
uddi2__get_USCOREauthToken get_authToken(soap, userid, passwd);
uddi2__authToken *authToken = get_authToken.send(server);
// Check if authorized
if (!authToken)
{
soap_print_fault(soap, stderr);
exit(1);
}
// Authorization info provided by server for this session
char *authInfo = authToken->authInfo;
// Step 2: Create a tModel for the WSDL to be published
uddi2__tModel tModel;
tModel.soap_default(soap);
// Create the tModel and service name
tModel.name = soap_new_uddi2__name(soap, -1);
tModel.name->__item = "...";
tModel.name->xml__lang_ = "en";
// Create XMethods description elements (see http://www.xmethods.net/ve2/UDDI.po)
uddi2__description *description = soap_new_uddi2__description(soap, 6);
description[0].__item = "SHORT DESCRIPTION: ...";
description[0].xml__lang_ = "en";
description[1].__item = "SHORT DESCRIPTION: ...";
description[1].xml__lang_ = "en";
description[2].__item = "USAGE NOTES: ...";
description[2].xml__lang_ = "en";
description[3].__item = "HOMEPAGE URL: ...";
description[3].xml__lang_ = "en";
description[4].__item = "CONTACT EMAIL: ...";
description[4].xml__lang_ = "en";
description[5].__item = "IMPLEMENTATION: ...";
description[5].xml__lang_ = "en";
// Add the four description elements to the tModel
tModel.description.push_back(description + 0);
tModel.description.push_back(description + 1);
tModel.description.push_back(description + 2);
tModel.description.push_back(description + 4);
// Add an overviewDoc element with description and overviewURL
tModel.overviewDoc = soap_new_uddi2__overviewDoc(soap, -1);
tModel.overviewDoc->soap_default(soap);
tModel.overviewDoc->description.push_back(soap_new_uddi2__description(soap, -1));
tModel.overviewDoc->description[0]->__item = "WSDL source document";
tModel.overviewDoc->description[0]->xml__lang_ = "en";
tModel.overviewDoc->overviewURL = "http://.../my.wsdl#bindingName";
// Omit identifier bag
tModel.identifierBag = NULL;
// Add a category with a WSDL-specific keyedReference
tModel.categoryBag = soap_new_uddi2__categoryBag(soap, -1);
tModel.categoryBag->soap_default(soap);
tModel.categoryBag->keyedReference.push_back(soap_new_uddi2__keyedReference(soap, -1));
tModel.categoryBag->keyedReference[0]->tModelKey = "...";
tModel.categoryBag->keyedReference[0]->keyName = "uddi-org:types";
tModel.categoryBag->keyedReference[0]->keyValue = "wsdlSpec";
tModel.authorizedName = "...";
tModel.operator_ = "...";
tModel.tModelKey = "...";
// Save the tModel
uddi2__save_USCOREtModel save_tModel(soap, tModel);
uddi2__tModelDetail *tModelDetail = save_tModel.send(server, authInfo);
// Step 3: Create a new service to be published
uddi2__businessService service;
service.soap_default(soap);
// Service name is the tModel name (XMethods)
service.name.push_back(tModel.name);
// Add two description elements to the service
service.description.push_back(description + 4);
service.description.push_back(description + 5);
// Create binding template
uddi2__bindingTemplate bindingTemplate;
bindingTemplate.soap_default(soap);
bindingTemplate.tModelInstanceDetails = soap_new_uddi2__tModelInstanceDetails(soap, -1);
bindingTemplate.tModelInstanceDetails->tModelInstanceInfo.push_back(soap_new_uddi2__tModelInstanceInfo(soap, -1));
bindingTemplate.tModelInstanceDetails->tModelInstanceInfo[0]->instanceDetails = NULL;
bindingTemplate.tModelInstanceDetails->tModelInstanceInfo[0]->tModelKey = tModel.tModelKey;
bindingTemplate.accessPoint = soap_new_uddi2__accessPoint(soap, -1);
bindingTemplate.accessPoint->__item = "...";
bindingTemplate.accessPoint->URLType = uddi2__URLType__http;
bindingTemplate.hostingRedirector = NULL;
bindingTemplate.serviceKey = "...";
bindingTemplate.bindingKey = "...";
// Add binding Template to service
service.bindingTemplates = soap_new_uddi2__bindingTemplates(soap, -1);
service.bindingTemplates->soap_default(soap);
service.bindingTemplates->bindingTemplate.push_back(&bindingTemplate);
service.categoryBag = NULL;
service.serviceKey = "...";
service.businessKey = "...";
// Save the service
uddi2__save_USCOREservice save_service(soap, service);
uddi2__serviceDetail *serviceDetail = save_service.send(server, authInfo);
// Step 4: Discard authorization token
uddi2__discard_USCOREauthToken discard_authToken(soap, authInfo);
uddi2__dispositionReport *dispositionReport = discard_authToken.send(server);
// Remove deserialized objects
soap_destroy(soap);
// Remove temporary data
soap_end(soap);
// Detach and free context
soap_done(soap);
free(soap);
return 0;
}
uddi2__accessPoint::URLType
enum uddi2__URLType URLType
Attribute URLType of type "urn:uddi-org:api_v2":URLType.
Definition uddi_v2.h:3153
uddi2__accessPoint::__item
char * __item
Definition uddi_v2.h:3151
uddi2__authToken
Schema urn:uddi-org:api_v2:"authToken".
Definition uddi_v2.h:2956
uddi2__authToken::authInfo
char * authInfo
Element reference "urn:uddi-org:api_v2":authInfo.
Definition uddi_v2.h:2958
uddi2__bindingTemplate
Schema urn:uddi-org:api_v2:"bindingTemplate".
Definition uddi_v2.h:1902
uddi2__bindingTemplate::hostingRedirector
uddi2__hostingRedirector * hostingRedirector
Element reference "urn:uddi-org:api_v2":hostingRedirector.
Definition uddi_v2.h:1911
uddi2__bindingTemplate::accessPoint
uddi2__accessPoint * accessPoint
Element reference "urn:uddi-org:api_v2":accessPoint.
Definition uddi_v2.h:1909
uddi2__bindingTemplate::tModelInstanceDetails
uddi2__tModelInstanceDetails * tModelInstanceDetails
Element reference "urn:uddi-org:api_v2":tModelInstanceDetails.
Definition uddi_v2.h:1906
uddi2__bindingTemplate::serviceKey
uddi2__serviceKey serviceKey
Attribute serviceKey of type "urn:uddi-org:api_v2":serviceKey.
Definition uddi_v2.h:1914
uddi2__bindingTemplate::bindingKey
uddi2__bindingKey bindingKey
Attribute bindingKey of type "urn:uddi-org:api_v2":bindingKey.
Definition uddi_v2.h:1916
uddi2__bindingTemplates::bindingTemplate
std::vector< uddi2__bindingTemplate * > bindingTemplate
Vector of uddi2__bindingTemplate* with length 0..unbounded.
Definition uddi_v2.h:1926
uddi2__businessService
Schema urn:uddi-org:api_v2:"businessService".
Definition uddi_v2.h:2002
uddi2__businessService::businessKey
uddi2__businessKey businessKey
Attribute businessKey of type "urn:uddi-org:api_v2":businessKey.
Definition uddi_v2.h:2014
uddi2__businessService::name
std::vector< uddi2__name * > name
Vector of uddi2__name* with length 0..unbounded.
Definition uddi_v2.h:2004
uddi2__businessService::serviceKey
uddi2__serviceKey serviceKey
Attribute serviceKey of type "urn:uddi-org:api_v2":serviceKey.
Definition uddi_v2.h:2012
uddi2__businessService::bindingTemplates
uddi2__bindingTemplates * bindingTemplates
Element reference "urn:uddi-org:api_v2":bindingTemplates.
Definition uddi_v2.h:2008
uddi2__businessService::categoryBag
uddi2__categoryBag * categoryBag
Element reference "urn:uddi-org:api_v2":categoryBag.
Definition uddi_v2.h:2010
uddi2__businessService::description
std::vector< uddi2__description * > description
Vector of uddi2__description* with length 0..unbounded.
Definition uddi_v2.h:2006
uddi2__categoryBag::keyedReference
std::vector< uddi2__keyedReference * > keyedReference
Vector of uddi2__keyedReference* with length 0..unbounded.
Definition uddi_v2.h:2034
uddi2__description
Schema urn:uddi-org:api_v2:"description".
Definition uddi_v2.h:3174
uddi2__description::__item
char * __item
Definition uddi_v2.h:3175
uddi2__description::xml__lang_
xml__lang xml__lang_
Attribute reference xml:lang.
Definition uddi_v2.h:3177
uddi2__discard_USCOREauthToken
Schema urn:uddi-org:api_v2:"discard_authToken".
Definition uddi_v2.h:2478
uddi2__dispositionReport
Schema urn:uddi-org:api_v2:"dispositionReport".
Definition uddi_v2.h:2082
uddi2__get_USCOREauthToken
Schema urn:uddi-org:api_v2:"get_authToken".
Definition uddi_v2.h:2660
uddi2__name::__item
char * __item
Definition uddi_v2.h:3219
uddi2__name::xml__lang_
xml__lang xml__lang_
Attribute reference xml:lang.
Definition uddi_v2.h:3221
uddi2__overviewDoc::overviewURL
char * overviewURL
Element reference "urn:uddi-org:api_v2":overviewURL.
Definition uddi_v2.h:2172
uddi2__overviewDoc::description
std::vector< uddi2__description * > description
Vector of uddi2__description* with length 0..unbounded.
Definition uddi_v2.h:2170
uddi2__save_USCOREservice
Schema urn:uddi-org:api_v2:"save_service".
Definition uddi_v2.h:2858
uddi2__save_USCOREtModel
Schema urn:uddi-org:api_v2:"save_tModel".
Definition uddi_v2.h:2880
uddi2__serviceDetail
Schema urn:uddi-org:api_v2:"serviceDetail".
Definition uddi_v2.h:3086
uddi2__tModelDetail
Schema urn:uddi-org:api_v2:"tModelDetail".
Definition uddi_v2.h:3118
uddi2__tModel
Schema urn:uddi-org:api_v2:"tModel".
Definition uddi_v2.h:2270
uddi2__tModel::tModelKey
uddi2__tModelKey tModelKey
Attribute tModelKey of type "urn:uddi-org:api_v2":tModelKey.
Definition uddi_v2.h:2282
uddi2__tModel::name
uddi2__name * name
Element reference "urn:uddi-org:api_v2":name.
Definition uddi_v2.h:2272
uddi2__tModel::identifierBag
uddi2__identifierBag * identifierBag
Element reference "urn:uddi-org:api_v2":identifierBag.
Definition uddi_v2.h:2278
uddi2__tModel::overviewDoc
uddi2__overviewDoc * overviewDoc
Element reference "urn:uddi-org:api_v2":overviewDoc.
Definition uddi_v2.h:2276
uddi2__tModel::description
std::vector< uddi2__description * > description
Vector of uddi2__description* with length 0..unbounded.
Definition uddi_v2.h:2274
uddi2__tModel::categoryBag
uddi2__categoryBag * categoryBag
Element reference "urn:uddi-org:api_v2":categoryBag.
Definition uddi_v2.h:2280
uddi2__tModel::authorizedName
char * authorizedName
Attribute authorizedName of type xs:string.
Definition uddi_v2.h:2286
uddi2__tModel::operator_
char * operator_
Attribute operator of type xs:string.
Definition uddi_v2.h:2284
uddi2__tModelInstanceDetails::tModelInstanceInfo
std::vector< uddi2__tModelInstanceInfo * > tModelInstanceInfo
Vector of uddi2__tModelInstanceInfo* with length 0..unbounded.
Definition uddi_v2.h:2328
uddi2__URLType__http
@ uddi2__URLType__http
xs:NMTOKEN value="http"
Definition uddi_v2.h:1847

To compile:

- wsdl2h -tuddi2-typemap.dat publish_v2.wsdl
- soapcpp2 -I.. -ppub publish_v2.h
- g++ -DWITH_OPENSSL -DWITH_NONAMESPACES -I.. -o example3 example3.cpp publish_v2.cpp pubC.cpp pubClient.cpp ../stdsoap2.cpp