⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wsaapi.c

📁 一款开源的soap库
💻 C
📖 第 1 页 / 共 3 页
字号:
/*wsaapi.cWS-Addressing plugin for stand-alone services.gSOAP XML Web services toolsCopyright (C) 2000-2006, Robert van Engelen, Genivia Inc., All Rights Reserved.This part of the software is released under one of the following licenses:GPL, the gSOAP public license, or Genivia's license for commercial use.--------------------------------------------------------------------------------gSOAP public license.The contents of this file are subject to the gSOAP Public License Version 1.3(the "License"); you may not use this file except in compliance with theLicense. You may obtain a copy of the License athttp://www.cs.fsu.edu/~engelen/soaplicense.htmlSoftware distributed under the License is distributed on an "AS IS" basis,WITHOUT WARRANTY OF ANY KIND, either express or implied. See the Licensefor the specific language governing rights and limitations under the License.The Initial Developer of the Original Code is Robert A. van Engelen.Copyright (C) 2000-2006, Robert van Engelen, Genivia Inc., All Rights Reserved.--------------------------------------------------------------------------------GPL license.This program is free software; you can redistribute it and/or modify it underthe terms of the GNU General Public License as published by the Free SoftwareFoundation; either version 2 of the License, or (at your option) any laterversion.This program is distributed in the hope that it will be useful, but WITHOUT ANYWARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR APARTICULAR PURPOSE. See the GNU General Public License for more details.You should have received a copy of the GNU General Public License along withthis program; if not, write to the Free Software Foundation, Inc., 59 TemplePlace, Suite 330, Boston, MA 02111-1307 USAAuthor contact information:engelen@genivia.com / engelen@acm.org--------------------------------------------------------------------------------A commercial use license is available from Genivia, Inc., contact@genivia.com--------------------------------------------------------------------------------*//**@mainpage- @ref wsa documents the wsa plugin for WS-Addressing (2004 spec) support.*//**@page wsa The wsa plugin for stand-alone services@section wsa_1 WS-Addressing SetupThe material in this section relates to the WS-Addressing specification 2004.To use the wsa plugin:-# Run wsdl2h -t typemap.dat on a WSDL of a service that requires WS-Addressing   headers. The typemap.dat file included in the gSOAP package is used to   recognize and translate Addressing header blocks.-# Run soapcpp2 on the header file produced by wsdl2h. To enable   addressing-based service operation selection, you MUST use soapcpp2 option   -a. This allows the service to dispatch methods based on the WS-Addressing   action information header value (assuming the wsa plugin is registered).-# (Re-)compile stdsoap2.c/pp, dom.c/pp, wsaapi.c and the generated   source files.-# Use the wsa plugin API functions described below.An example wsa client/server application can be found in samples/wsa.To use WS-Addressing, the gSOAP header file for a service should declare a SOAPHeader with the required WS-Addressing information headers. The header file isautomatically generated by wsdl2h for a set of WSDLs. The gSOAP header file isfurther processed by soapcpp2 to generate the binding codes.The SOAP Header structure contains the WS-Addressing information headersextracted from the WSDL and the WS-Addressing specification. For example:@code#import "soap12.h"#import "wsa.h"struct SOAP_ENV__Header{                 _wsa__MessageID  wsa__MessageID 0;                 _wsa__RelatesTo *wsa__RelatesTo 0;                 _wsa__From      *wsa__From      0;  mustUnderstand _wsa__ReplyTo   *wsa__ReplyTo   0;  mustUnderstand _wsa__FaultTo   *wsa__FaultTo   0;  mustUnderstand _wsa__To         wsa__To        0;  mustUnderstand _wsa__Action     wsa__Action    0;};@endcodeThe SOAP Header struct is automatically generated by wsdl2h from a WSDL.However, it must be manually defined when creating new services from gSOAPheader files. The gSOAP header file is processed with soapcpp2 to generate theclient-side and/or server-side binding code.Note that the wsa.h header file in the import directory declares theWS-Addressing information header elements and types. The soap12.h headerfile enables SOAP 1.2 messaging. Note that the mustUnderstand qualifierensures that the information headers must be understood by a receiving SOAPprocessor.For developers: the WS-Addressing header blocks in wsa.h were generated fromthe WS-Addressing schema with the wsdl2h tool and WS/WS-typemap.dat as follows:@code    $ wsdl2h -cegy -o wsa.h -t WS/WS-typemap.dat WS/WS-Addressing.xsd@endcode@section wsa_2 Client-side Usage@subsection wsa_2_1 Formulating WS-Addressing Information HeadersTo associate WS-Addressing information headers with service operations, theSOAP Header struct must have been defined and for each service operation thatuses WS-Addressing method-header-part directives should be used in the gSOAPheader file of the service as follows:@code#import "wsa.h"struct SOAP_ENV__Header { ... };//gsoap ns service method-header-part: example wsa__MessageID//gsoap ns service method-header-part: example wsa__RelatesTo//gsoap ns service method-header-part: example wsa__From//gsoap ns service method-header-part: example wsa__ReplyTo//gsoap ns service method-header-part: example wsa__FaultTo//gsoap ns service method-header-part: example wsa__To//gsoap ns service method-header-part: example wsa__Action//gsoap ns service method-action: example urn:example/examplePort/exampleint ns__example(char *in, struct ns__exampleResponse *out);@endcodeIn the client-side code, the WS-Addressing information headers are set withsoap_wsa_request() by passing an optional message UUID string, a mandatorydestination address URI string, and a mandatory request action URI string. Thewsa plugin should be registered with the currenct soap struct context. Anoptional source address information header can be added withsoap_wsa_add_From() (must be invoked after the soap_wsa_request call).For example:@codesoap_register_plugin(soap, soap_wsa);soap_wsa_request(soap, RequestMessageID, ToAddress, RequestAction);soap_wsa_add_From(soap, FromAddress); // optional: add a 'From' addressif (soap_call_ns__example(soap, ToAddress, NULL, ...))  soap_print_fault(soap, stderr); // an error occurredelse  // process the response @endcode@subsection wsa_2_2 Information Headers for Relaying Server ResponsesTo relay the response to another destination, the WS-Addressing ReplyToinformation header is added with soap_wsa_add_ReplyTo() by passing a replyaddress URI string. The service returns HTTP 202 ACCEPTED to the client whenthe response message relay was successful.For example:@codesoap_register_plugin(soap, soap_wsa);soap_wsa_request(soap, RequestMessageID, ToAddress, RequestAction);soap_wsa_add_From(soap, FromAddress); // optional: add a 'From' addresssoap_wsa_add_ReplyTo(soap, ReplyToAddress);if (soap_call_ns__example(soap, ToAddress, NULL, ...)){  if (soap->error == 202) // HTTP ACCEPTED    printf("Request was accepted and results were forwarded\n");  else    soap_print_fault(soap, stderr); // an error occurred}else  // error: for some reason the response was not relayed@endcodeNote: the response message will be relayed when the From address is absent ordifferent than the ReplyTo address@subsection wsa_2_3 Information Headers for Relaying Server FaultsTo relay a server fault message to another destination, the WS-AddressingFaultTo information header is added with soap_wsa_add_FaultTo() by passing arelay address URI string. The service returns HTTP 202 ACCEPTED to the clientwhen the fault was relayed.For example:@codesoap_register_plugin(soap, soap_wsa);soap_wsa_request(soap, RequestMessageID, ToAddress, RequestAction);soap_wsa_add_From(soap, FromAddress); // optional: add a 'From' addresssoap_wsa_add_FaultTo(soap, FaultToAddress);if (soap_call_ns__example(soap, ToAddress, NULL, ...)){  if (soap->error == 202) // HTTP ACCEPTED    printf("A fault occurred and the fault details were forwarded\n");  else    soap_print_fault(soap, stderr); // a connection error occurred}else  // process response @endcodeNote that the call can still return a fault, such as a connection error whenthe service is not responding. In addition to the fault relay, the responsescan be relayed with soap_wsa_add_ReplyTo().@section wsa_3 Server-side UsageThe wsa plugin should be registered with:@codesoap_register_plugin(soap, soap_wsa);@endcodeOnce the plugin is registered, the soap_bind(), soap_accept(), and soap_serve() functions can be called to process requests.Important: to dispatch service operations based on the WS-Addressing wsa:Actioninformation header, use soapcpp2 option -a. The generates a new dispatcher (insoapServer.c) based on the action value.A service operation implementation should use soap_wsa_check() to verify thevalidity of the WS-Addressing information headers in the SOAP request message.To allow response message to be automatically relayed based on the ReplyToinformation header, the service operation should return soap_wsa_reply() withan optional message UUID string and a mandatory response action string.For example:@codeint ns__example(struct soap *soap, char *in, struct ns__exampleResponse *out){ if (soap_wsa_check(soap))    return soap->error;  // ... service logic  return soap_wsa_reply(soap, ResponseMessageID, ResponseAction);}@endcodeTo return a SOAP fault that is automatically relayed to a fault service basedon the FaultTo information header, the soap_wsa_sender_fault(),soap_wsa_receiver_fault(), soap_wsa_sender_fault_subcode(), andsoap_wsa_receiver_fault_subcode() functions should be used instead of thesoap_sender_fault(), soap_receiver_fault(), soap_sender_fault_subcode(), andsoap_receiver_fault_subcode(), respectively.For example:@codeint ns__example(struct soap *soap, char *in, struct ns__exampleResponse *out){ if (soap_wsa_check(soap))    return soap->error;  // ... service logic  // ... an error occurred, need to return fault possibly to fault service:    return soap_wsa_sender_fault(soap, "Exception in service operation", NULL);  // ... normal execution continues  return soap_wsa_reply(soap, ResponseMessageID, ResponseAction);}@endcode@section wsa_4 Implementing a Server for Handling ReplyTo Response MessagesTo implement a separate server for handling relayed SOAP response messagesbased on the ReplyTo information header in the request message, the gSOAPheader file should include a one-way service operation for the responsemessage.For example, suppose a service operation returns an exampleResponse message. Wedeclare the one-way exampleResponse operation as follows:@code#import "wsa.h"struct SOAP_ENV__Header { ... };

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -