# WebObjects/Web Services/Problems
## Problems

This section describes some problems and bugs that sometimes occur when using WebObjects Web Services.

### DirectToWebService can't return a WSDL with secure HTTPS references in it

    Authors: Francis Labrie
    Affected products: WebObjects 5.2.x, 5.3.x
    Bug reference: rdar://3546304

#### Problem:

A DirectToWebService defined Web Services doesn't return correct WSDL document, even if the correct procedure (see Secure Web Services) is followed. So only classes oriented Web Services manually registered with the com.webobjects.appserver.WOWebServiceRegistrar class seems to generate a correct WSDL.

#### Solution:

Darel Lee from Apple told me that right now, the dynamic WSDL generation is not exposed to developers so there currently isn't a clean solution to perform this. One workaround is to hardcode rules (of com.webobjects.directtoweb.Assignment type) with the serviceLocationURL key for each operation that you want to use secure HTTPS references. For instance:
If you need all operation to be called using the secure protocol, you can also define a more generic rule like this one:

### SOAP serializers and deserializers registered with WOWebServiceRegistrar class doesn't appear in the WSDL schema

    Authors: Francis Labrie
    Affected products: WebObjects 5.2.x, 5.3.x
    Bug reference: rdar://3546330

#### Problem:

Custom SOAP serializers and deserializers registered to Web Services with com.webobjects.appserver.WOWebServiceRegistrar class are never added to the types / schema definition of the WSDL. The only type definitions shown are the following:

#### Solution:

I don't know any dynamic workaround right now... But a static and complete WSDL can be shared through a direct action. It's not very handy though...

### DirectToWebService can't return a WSDL with custom namespace and definitions name in it

    Authors: Francis Labrie
    Affected products: WebObjects 5.2.x, 5.3.x
    Bug reference:

#### Problem:

A DirectToWebService defined Web Services can't return a WSDL with custom values for properties like namespaces and definitions name. Worse, the generated namespace can even contains WebObjects application instance number or the wrong hostname.

#### Solution:

Base on a tips from Darel Lee, I've found in the com.webobjects.webservices.generation._private.WOWSDLTemplate class some extras key definitions read from the user.d2wmodel DirectToWebService rule file. For instance:
* serviceLocationURL: a key that allow the setting of the location URL for an operation. This is usefull if you need your WebServices to be reached using a secure HTTPS reference;
* WSDLDefinitionName: a key that allow the definitions name change. So instead of having "ServiceNameDefinition", you can set this value;
* WSDLTargetNamespace: a key that allow the namespace change. This is the most usefull: you can avoid dynamic generation depending on WebObjects HTTP Adaptor? with this.
Here is an example of rule definition changing the above values:

### WOWebServiceClient class can't connect to a server that requires an authentication (WO 5.2.x, Bug ID 3568441)

    Authors: Francis Labrie
    Affected products: WebObjects 5.2.x, 5.3.x
    Bug reference: rdar://3568441

#### Problem:

The com.webobjects.webservices.client.WOWebServiceClient class can't connect to a server that requires a Basic HTTP Authentication despite the fact this class offers a way to register a security delegate (see setSecurityDelegateForServiceNamed(Object, String) instance method).
Normally, the processClientRequest(MessageContext) delegate method (see com.webobjects.webservices.support.WOSecurityDelegate interface documentation) would allow an easy way to set a username and a password to the message context. But there is a problem related to the design of the class: to register a security delegate, the WOWebServiceClient class has to fetch the Web Services Definition Language (WSDL) XML document. But to get access to this WSDL, an authentication header must be set. This is the classic chicken and egg problem...

#### Solution:

The best would be to add a default method to WOWebServiceClient class to register a default security delegate that is not related to a service name before the class fetch the WSDL. But unfortunately, all key methods that would allow this kind of behavior change are privates, so subclassing is not a solution...
But a workaround is still possible:
* Fetch the WSDL document yourself and store it to the local filesystem, using the java.net.URL instance and setting up the Basic HTTP Authentication header field of the java.net.URLConnection yourself;
* Instanciate another java.net.URL class that refer to the local WSDL document file;
* Instanciate the com.webobjects.webservices.client.WOWebServiceClient class using the file URL;
* Set for each service a security delegate that will add the proper credential information for the Basic HTTP Authentication.
That's it. It looks like a big hack, but it works...

### Web Services can't return a WSDL with secure HTTPS references specifying port other than the default 443

    Authors: Francis Labrie
    Affected products: WebObjects 5.2.x, 5.3.x
    Bug reference: rdar://4196417

#### Problem:

HTTPS protocol references can be published in Web Services WSDL. But unfortunately, WebObjects seems to ignore ports other than the default 443.
This problem is related to the bad way com.webobjects.appserver.WORequest build the URL prefix: if the protocol is secure and no port (i.e. 0) is set when calling the _completeURLPrefix(StringBuffer,boolean,int) method, the port will always be 443. Unfortunately, Web Services com.webobjects.appserver._private.WOWebService class seems to call this method without setting the port number.

#### Solution:

To work around this bug, you can subclass the com.webobjects.appserver.WORequest class like this: