Sophie

Sophie

distrib > Mandriva > 2007.0 > i586 > media > contrib-release > by-pkgid > 9f5c7ae460878d5070e65a29704c26cd > files > 372

gsoap-2.7.8c-1mdv2007.0.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>gSOAP UDDI v2: Code Example 3: Publishing a WSDL and service on XMethods</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3.8 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
<h1><a class="anchor" name="example3">Code Example 3: Publishing a WSDL and service on XMethods</a></h1>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.<p>
<div class="fragment"><pre><span class="preprocessor">#include "pubH.h"</span>

<span class="keyword">const</span> <span class="keywordtype">char</span> *server = <span class="stringliteral">"https://uddi.xmethods.net/publish"</span>;

<span class="keyword">const</span> <span class="keywordtype">char</span> *userid = <span class="stringliteral">"..."</span>; <span class="comment">// user ID to access UDDI server</span>
<span class="keyword">const</span> <span class="keywordtype">char</span> *passwd = <span class="stringliteral">"..."</span>; <span class="comment">// password to access UDDI server</span>

<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
{ 
  <span class="comment">// Create a gSOAP context</span>
  <span class="keyword">struct </span>soap *soap = soap_new();

  <span class="comment">// Setup SSL context (optional) to verify server's credentials</span>
  <span class="keywordflow">if</span> (soap_ssl_client_context(soap, SOAP_SSL_DEFAULT, NULL, NULL, <span class="stringliteral">"cacerts.pem"</span>, NULL, NULL))
  { 
    soap_print_fault(soap, stderr);
    exit(1);
  }

  <span class="comment">// Step 1: Get an authorization token from the UDDI server</span>
  <a class="code" href="classuddi2____get___u_s_c_o_r_eauth_token.html">uddi2__get_USCOREauthToken</a> get_authToken(soap, userid, passwd);
  <a class="code" href="classuddi2____auth_token.html">uddi2__authToken</a> *authToken = get_authToken.send(server);

  <span class="comment">// Check if authorized</span>
  <span class="keywordflow">if</span> (!authToken)
  {
    soap_print_fault(soap, stderr);
    exit(1);
  }

  <span class="comment">// Authorization info provided by server for this session</span>
  <span class="keywordtype">char</span> *authInfo = authToken-&gt;<a class="code" href="classuddi2____auth_token.html#o0">authInfo</a>;

  <span class="comment">// Step 2: Create a tModel for the WSDL to be published</span>
  <a class="code" href="classuddi2____t_model.html">uddi2__tModel</a> tModel;
  tModel.soap_default(soap);

  <span class="comment">// Create the tModel and service name</span>
  tModel.<a class="code" href="classuddi2____t_model.html#o0">name</a> = soap_new_uddi2__name(soap, -1);
  tModel.<a class="code" href="classuddi2____t_model.html#o0">name</a>-&gt;<a class="code" href="classuddi2____name.html#o0">__item</a> = <span class="stringliteral">"..."</span>;
  tModel.<a class="code" href="classuddi2____t_model.html#o0">name</a>-&gt;<a class="code" href="classuddi2____name.html#o1">xml__lang_</a> = <span class="stringliteral">"en"</span>;

  <span class="comment">// Create XMethods description elements (see http://www.xmethods.net/ve2/UDDI.po)</span>
  <a class="code" href="classuddi2____description.html">uddi2__description</a> *description = soap_new_uddi2__description(soap, 6);
  description[0].<a class="code" href="classuddi2____description.html#o0">__item</a> = <span class="stringliteral">"SHORT DESCRIPTION: ..."</span>;
  description[0].<a class="code" href="classuddi2____description.html#o1">xml__lang_</a> = <span class="stringliteral">"en"</span>;
  description[1].<a class="code" href="classuddi2____description.html#o0">__item</a> = <span class="stringliteral">"SHORT DESCRIPTION: ..."</span>;
  description[1].<a class="code" href="classuddi2____description.html#o1">xml__lang_</a> = <span class="stringliteral">"en"</span>;
  description[2].<a class="code" href="classuddi2____description.html#o0">__item</a> = <span class="stringliteral">"USAGE NOTES: ..."</span>;
  description[2].<a class="code" href="classuddi2____description.html#o1">xml__lang_</a> = <span class="stringliteral">"en"</span>;
  description[3].<a class="code" href="classuddi2____description.html#o0">__item</a> = <span class="stringliteral">"HOMEPAGE URL: ..."</span>;
  description[3].<a class="code" href="classuddi2____description.html#o1">xml__lang_</a> = <span class="stringliteral">"en"</span>;
  description[4].<a class="code" href="classuddi2____description.html#o0">__item</a> = <span class="stringliteral">"CONTACT EMAIL: ..."</span>;
  description[4].<a class="code" href="classuddi2____description.html#o1">xml__lang_</a> = <span class="stringliteral">"en"</span>;
  description[5].<a class="code" href="classuddi2____description.html#o0">__item</a> = <span class="stringliteral">"IMPLEMENTATION: ..."</span>;
  description[5].<a class="code" href="classuddi2____description.html#o1">xml__lang_</a> = <span class="stringliteral">"en"</span>;

  <span class="comment">// Add the four description elements to the tModel</span>
  tModel.<a class="code" href="classuddi2____t_model.html#o1">description</a>.push_back(description + 0);
  tModel.<a class="code" href="classuddi2____t_model.html#o1">description</a>.push_back(description + 1);
  tModel.<a class="code" href="classuddi2____t_model.html#o1">description</a>.push_back(description + 2);
  tModel.<a class="code" href="classuddi2____t_model.html#o1">description</a>.push_back(description + 4);

  <span class="comment">// Add an overviewDoc element with description and overviewURL</span>
  tModel.<a class="code" href="classuddi2____t_model.html#o2">overviewDoc</a> = soap_new_uddi2__overviewDoc(soap, -1);
  tModel.<a class="code" href="classuddi2____t_model.html#o2">overviewDoc</a>-&gt;soap_default(soap);
  tModel.<a class="code" href="classuddi2____t_model.html#o2">overviewDoc</a>-&gt;<a class="code" href="classuddi2____overview_doc.html#o0">description</a>.push_back(soap_new_uddi2__description(soap, -1));
  tModel.<a class="code" href="classuddi2____t_model.html#o2">overviewDoc</a>-&gt;<a class="code" href="classuddi2____overview_doc.html#o0">description</a>[0]-&gt;__item = <span class="stringliteral">"WSDL source document"</span>;
  tModel.<a class="code" href="classuddi2____t_model.html#o2">overviewDoc</a>-&gt;<a class="code" href="classuddi2____overview_doc.html#o0">description</a>[0]-&gt;xml__lang_ = <span class="stringliteral">"en"</span>;
  tModel.<a class="code" href="classuddi2____t_model.html#o2">overviewDoc</a>-&gt;<a class="code" href="classuddi2____overview_doc.html#o1">overviewURL</a> = <span class="stringliteral">"http://.../my.wsdl#bindingName"</span>;

  <span class="comment">// Omit identifier bag</span>
  tModel.<a class="code" href="classuddi2____t_model.html#o3">identifierBag</a> = NULL;

  <span class="comment">// Add a category with a WSDL-specific keyedReference</span>
  tModel.<a class="code" href="classuddi2____t_model.html#o4">categoryBag</a> = soap_new_uddi2__categoryBag(soap, -1);
  tModel.<a class="code" href="classuddi2____t_model.html#o4">categoryBag</a>-&gt;soap_default(soap);
  tModel.<a class="code" href="classuddi2____t_model.html#o4">categoryBag</a>-&gt;<a class="code" href="classuddi2____category_bag.html#o0">keyedReference</a>.push_back(soap_new_uddi2__keyedReference(soap, -1));
  tModel.<a class="code" href="classuddi2____t_model.html#o4">categoryBag</a>-&gt;<a class="code" href="classuddi2____category_bag.html#o0">keyedReference</a>[0]-&gt;tModelKey = <span class="stringliteral">"..."</span>;
  tModel.<a class="code" href="classuddi2____t_model.html#o4">categoryBag</a>-&gt;<a class="code" href="classuddi2____category_bag.html#o0">keyedReference</a>[0]-&gt;keyName = <span class="stringliteral">"uddi-org:types"</span>;
  tModel.<a class="code" href="classuddi2____t_model.html#o4">categoryBag</a>-&gt;<a class="code" href="classuddi2____category_bag.html#o0">keyedReference</a>[0]-&gt;keyValue = <span class="stringliteral">"wsdlSpec"</span>;

  tModel.<a class="code" href="classuddi2____t_model.html#o7">authorizedName</a> = <span class="stringliteral">"..."</span>;
  tModel.<a class="code" href="classuddi2____t_model.html#o6">operator_</a> = <span class="stringliteral">"..."</span>;
  tModel.<a class="code" href="classuddi2____t_model.html#o5">tModelKey</a> = <span class="stringliteral">"..."</span>;

  <span class="comment">// Save the tModel</span>
  <a class="code" href="classuddi2____save___u_s_c_o_r_et_model.html">uddi2__save_USCOREtModel</a> save_tModel(soap, tModel);
  <a class="code" href="classuddi2____t_model_detail.html">uddi2__tModelDetail</a> *tModelDetail = save_tModel.send(server, authInfo);

  <span class="comment">// Step 3: Create a new service to be published</span>
  <a class="code" href="classuddi2____business_service.html">uddi2__businessService</a> service;
  service.soap_default(soap);

  <span class="comment">// Service name is the tModel name (XMethods)</span>
  service.<a class="code" href="classuddi2____business_service.html#o0">name</a>.push_back(tModel.<a class="code" href="classuddi2____t_model.html#o0">name</a>);

  <span class="comment">// Add two description elements to the service</span>
  service.<a class="code" href="classuddi2____business_service.html#o1">description</a>.push_back(description + 4);
  service.<a class="code" href="classuddi2____business_service.html#o1">description</a>.push_back(description + 5);

  <span class="comment">// Create binding template</span>
  <a class="code" href="classuddi2____binding_template.html">uddi2__bindingTemplate</a> bindingTemplate;
  bindingTemplate.soap_default(soap);
  bindingTemplate.<a class="code" href="classuddi2____binding_template.html#o1">tModelInstanceDetails</a> = soap_new_uddi2__tModelInstanceDetails(soap, -1);
  bindingTemplate.<a class="code" href="classuddi2____binding_template.html#o1">tModelInstanceDetails</a>-&gt;<a class="code" href="classuddi2____t_model_instance_details.html#o0">tModelInstanceInfo</a>.push_back(soap_new_uddi2__tModelInstanceInfo(soap, -1));
  bindingTemplate.<a class="code" href="classuddi2____binding_template.html#o1">tModelInstanceDetails</a>-&gt;<a class="code" href="classuddi2____t_model_instance_details.html#o0">tModelInstanceInfo</a>[0]-&gt;instanceDetails = NULL;
  bindingTemplate.<a class="code" href="classuddi2____binding_template.html#o1">tModelInstanceDetails</a>-&gt;<a class="code" href="classuddi2____t_model_instance_details.html#o0">tModelInstanceInfo</a>[0]-&gt;tModelKey = tModel.<a class="code" href="classuddi2____t_model.html#o5">tModelKey</a>;
  bindingTemplate.<a class="code" href="classuddi2____binding_template.html#o2">accessPoint</a> = soap_new_uddi2__accessPoint(soap, -1);
  bindingTemplate.<a class="code" href="classuddi2____binding_template.html#o2">accessPoint</a>-&gt;<a class="code" href="classuddi2____access_point.html#o0">__item</a> = <span class="stringliteral">"..."</span>;
  bindingTemplate.<a class="code" href="classuddi2____binding_template.html#o2">accessPoint</a>-&gt;<a class="code" href="classuddi2____access_point.html#o1">URLType</a> = <a class="code" href="uddi__v2_8h.html#a49a11">uddi2__URLType__http</a>;
  bindingTemplate.<a class="code" href="classuddi2____binding_template.html#o3">hostingRedirector</a> = NULL;
  bindingTemplate.<a class="code" href="classuddi2____binding_template.html#o4">serviceKey</a> = <span class="stringliteral">"..."</span>;
  bindingTemplate.<a class="code" href="classuddi2____binding_template.html#o5">bindingKey</a> = <span class="stringliteral">"..."</span>;

  <span class="comment">// Add binding Template to service</span>
  service.<a class="code" href="classuddi2____business_service.html#o2">bindingTemplates</a> = soap_new_uddi2__bindingTemplates(soap, -1);
  service.<a class="code" href="classuddi2____business_service.html#o2">bindingTemplates</a>-&gt;soap_default(soap);
  service.<a class="code" href="classuddi2____business_service.html#o2">bindingTemplates</a>-&gt;<a class="code" href="classuddi2____binding_templates.html#o0">bindingTemplate</a>.push_back(&amp;bindingTemplate);

  service.<a class="code" href="classuddi2____business_service.html#o3">categoryBag</a> = NULL;
  service.<a class="code" href="classuddi2____business_service.html#o4">serviceKey</a> = <span class="stringliteral">"..."</span>;
  service.<a class="code" href="classuddi2____business_service.html#o5">businessKey</a> = <span class="stringliteral">"..."</span>;

  <span class="comment">// Save the service</span>
  <a class="code" href="classuddi2____save___u_s_c_o_r_eservice.html">uddi2__save_USCOREservice</a> save_service(soap, service);
  <a class="code" href="classuddi2____service_detail.html">uddi2__serviceDetail</a> *serviceDetail = save_service.send(server, authInfo);

  <span class="comment">// Step 4: Discard authorization token</span>
  <a class="code" href="classuddi2____discard___u_s_c_o_r_eauth_token.html">uddi2__discard_USCOREauthToken</a> discard_authToken(soap, authInfo);
  <a class="code" href="classuddi2____disposition_report.html">uddi2__dispositionReport</a> *dispositionReport = discard_authToken.send(server);

  <span class="comment">// Remove deserialized objects</span>
  soap_destroy(soap);

  <span class="comment">// Remove temporary data</span>
  soap_end(soap);

  <span class="comment">// Detach and free context</span>
  soap_done(soap);
  free(soap);

  <span class="keywordflow">return</span> 0;
}
</pre></div>To compile:<ul>
<li>wsdl2h -tuddi2-typemap.dat publish_v2.wsdl</li><li>soapcpp2 -I.. -ppub publish_v2.h</li><li>g++ -DWITH_OPENSSL -DWITH_NONAMESPACES -I.. -o example3 example3.cpp publish_v2.cpp pubC.cpp pubClient.cpp ../stdsoap2.cpp </li></ul>
<hr size="1"><address style="align: right;"><small>Generated on Wed Aug 17 16:17:00 2005 for gSOAP UDDI v2 by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 ></a> 1.3.8 </small></address>
</body>
</html>