function wpws_createWSDL()
{
    $wsdl = wpws_getWSDLfromTemplate();
    // Should this operation fail, write permission aren't given.
    // In this case you need to create the customized WSDL on the base
    // of the template file on your own.
    @file_put_contents(WPWS_WSDL, $wsdl);
}
/**
 * Catches index.php/wpws requests, stops further execution by WordPress
 * and handles the request depending on the request type.
 *
 * The are 3 types of treatment:
 * 1) User hasn't requested a WSDL file nor a SOAP operation => HTML output of general information
 * 2) User has requested requested WSDL file => deliveration by SoapServer instance
 * 3) User has submited a SOAP operation request => treatment by SoapServer instance
 *
 * Because the caller needs to know where he can access the service
 * the correct blog address needs to be specified in the service port of the WSDL.
 * For that reason only a template WSDL file exists. Should the script detect that
 * a customized WSDL with the correct address doesn't exist it creates it
 * by making a copy of the template WSDL and by replacing the address placeholder.
 * Should you ever need to reallocate the Blog simply delete the wpws.wsdl but provoke it's recreation.
 */
function wpws_handle_request($wp)
{
    // Look for the magic /wpws string in the $_SERVER variable
    $wpws_found = false;
    $wsdl_requested = false;
    unset($_SERVER['argv']);
    foreach ($_SERVER as $val) {
        if (strlen($val) >= 5 && substr($val, 0, 5) == "/wpws") {
            $wpws_found = true;
            if (isset($_SERVER["QUERY_STRING"]) && strpos($_SERVER["QUERY_STRING"], "?wsdl") !== false) {
                $wsdl_requested = true;
            }
            break;
        }
    }
    if ($wpws_found) {
        // make sure the QUERY_STRING is correctly set to ?wsdl so the SoapServer instance delivers the wsdl file
        if ($wsdl_requested) {
            header("Content-type: text/xml");
            echo wpws_getWSDLfromTemplate();
            exit;
        } else {
            if (!isset($_SERVER["HTTP_SOAPACTION"])) {
                // client hasn't requested a SOAP operation
                // return HTML page
                include WPWS_INDEX_FILE;
            } else {
                // Create a customized WSDL file on disk
                // so the SoapServer can take this copy to load from.
                wpws_createWSDL();
                // SoapServer handles both: deliveration of the requested WSDL file
                // and execution of SOAP operations
                header("Content-type: text/xml");
                require_once WPWS_SOAP_SERVER_FILE;
                ini_set("soap.wsdl_cache_enabled", "0");
                $server = new SoapServer(WPWS_WSDL, array("cache_wsdl" => WSDL_CACHE_NONE));
                $server->setClass(WPWS_SOAP_SERVER_CLASS);
                $server->handle();
            }
        }
        exit;
    }
    // no wpws-request, go on with WordPress execution
}
/**
 * Catches index.php/wpws requests, stops further execution by WordPress
 * and handles the request depending on the request type.
 *
 * The are 3 types of treatment:
 * 1) User hasn't requested a WSDL file nor a SOAP operation => HTML output of general information
 * 2) User has requested requested WSDL file => deliveration by SoapServer instance
 * 3) User has submited a SOAP operation request => treatment by SoapServer instance
 *
 * Because the caller needs to know where he can access the service
 * the correct blog address needs to be specified in the service port of the WSDL.
 * For that reason only a template WSDL file exists. Should the script detect that
 * a customized WSDL with the correct address doesn't exist it creates it
 * by making a copy of the template WSDL and by replacing the address placeholder.
 * Should you ever need to reallocate the Blog simply delete the wpws.wsdl but provoke it's recreation.
 */
function wpws_handle_request($wp)
{
    // Look for the magic /wpws string in the $_SERVER variable
    $wpws_found = false;
    $wsdl_requested = false;
    foreach ($_SERVER as $val) {
        if (is_string($val) && strlen($val) >= 5 && substr($val, 0, 5) == "/wpws") {
            $wpws_found = true;
            if (isset($_SERVER["QUERY_STRING"]) && strpos($_SERVER["QUERY_STRING"], "?wsdl") !== false) {
                $wsdl_requested = true;
            }
            break;
        }
    }
    if ($wpws_found) {
        // make sure the QUERY_STRING is correctly set to ?wsdl so the SoapServer instance delivers the wsdl file
        if ($wsdl_requested) {
            header("Content-type: text/xml");
            echo wpws_getWSDLfromTemplate();
            exit;
        } else {
            if (!isset($_SERVER["HTTP_SOAPACTION"])) {
                //  wpws_getindex();
                include WPWS_INDEX_FILE;
            } else {
                // Create a customized WSDL file on disk
                // so the SoapServer can take this copy to load from.
                //	wpws_createWSDL();
                // SoapServer handles both: deliveration of the requested WSDL file
                // and execution of SOAP operations
                // header("Content-type: text/xml");
                require_once WPWS_SOAP_SERVER_FILE;
            }
        }
        exit;
    }
    // no wpws-request, go on with WordPress execution*/
}