|
Borland released the second patch that is significant to Delphi 6 and has greatly improved soap/Web service development, for details, see Delphi 6.02 preemptive research-bizsnap/soap/WebService 4-significance of patch 2 #. However, I did not mention one aspect in that article, that is, using soap for multi-layer application development. At that time, I just gave a rough look at this part, I didn't find anything different from that before the patch, so I didn't care about it. Not long ago, when a user called liaoqian sent me a mail asking me about this issue, I noticed that Delphi 6 Update 2 # had a big change in this part (not on the surface of course) and there was a small bug.
First, we will create a WebService layer-3 data application following the example in "Delphi 6 preemptive Research -- bizsnap/soap/WebService 3 -- using soap to implement layer-3 database applications. Select "no" when the displayed dialog box automatically asks whether to generate a server interface, and then create the SOAP server data module. Other operations are the same as those in "3. Enter http: // localhost: 1024/demo3.wadsoapdemo3/WSDL in IE. The following interface list is displayed. Compared with the article 3, an iappserversoap interface is added, and the namespace URI of its iwsdlpublish interface is also different.
| Port type |
Namespace URI |
Documentation |
WSDL |
| Iappserver |
URN: Midas-iappserver |
|
Iappserver |
| Iappserversoap |
Http://www.borland.com/namespaces/Types |
|
Iappserversoap |
| Isoapdemo3dm |
URL: SvrDMSoap-ISoapDemo3DM |
|
Isoapdemo3dm |
| Iwsdlpublish |
Http://www.borland.com/namespaces/Types |
Lists all the porttypes published by this service |
Iwsdlpublish |
If you pay attention to it, you can also find a problem, that is, entering http: // localhost: 1024/demo3.wadsoapdemo3 won't see a page like WebService written in Delphi 6.02, which is a bit abnormal.
When the client program is compiled, the problem occurs: In the clientdataset providername attribute drop-down, no available providername will be seen, however, a transient server form indicates that the server is running. You can see the following SOAP error response by viewing the web app debugger record:
<?xml version="1.0" encoding='UTF-8'?><soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" > <soap-env:body> <soap-env:fault> <faultcode>SOAP-ENV:Server</faultcode> <faultstring>No invokable class registered that implements interface SOAPMidas.IAppServerSOAP of (soap action/path) "http://www.borland.com/namespaces/Types-IAppServerSOAP" </faultstring> </soap-env:fault> </soap-env:body></soap-env:envelope>
Note the information in the faultstring flag, which indicates the error because "no registered iappserversoap interface implementation class can be called ". If you ignore this problem, write datasetprovider1 to the providername attribute of clientdataset1, and set the active attribute of clientdataset1 to true, an exception occurs directly. The content of this exception is the content of the above faultstring.
I like almost all Borland products, including Delphi, and trust Borland very much. This feeling comes from the dozens of different Borland products I used in year 78 and their different versions, so I don't like some people who complain about bugs in development tools with no reason when they encounter problems. Although there are many rumors about how many bugs Borland products have, in factIf there is software, there will be bugs.I am not saying that Borland has no bugs. Borland also has bugs. It has been mentioned several times on this site. Does Microsoft have no bugs?
But this time, I am almost certainly a bug brought about by Delphi 6 Update 2, because before patching 2 #, I did it step by step completely according to the above practice, without any problems, this problem occurs when patch 2 # is installed. Even so, I still need to find specific evidence to prove that this is a bug and find a solution. So I read some soap-related source code from Delphi 6.02 and debug it.
Appendix: View and debug the source code
View soap source code settings: Select Tools | environment options in Delphi 6 and select the library page. Add the path $ (Delphi)/source/soap to the browsing path, then, you can use Ctrl + mouseleftbutton in the program to quickly jump to the corresponding soap source code file.
Source code debugging settings: select project in Delph 6 | options select the compiler page, select the use DEBUG dcus option in the debugging box, and re-compile the program, you can debug and enter the source code of VCL.
Tracking and debugging showed that the exception occurred in procedure thttpsoappascalinvoker. dispatchsoap in the soaphttppasinv unit:
... if IntfInfo = nil then raise Exception.CreateFmt(SInvInterfaceNotReg, [SoapAction]) else if InvClassType = nil then RaiseNoIntfException(SoapAction) ...
Because invclasstype is nil, this exception occurs. The provided information is the same as the previous error information: The iappserversoap interface implementation class does not exist or is not registered. So I found the definition of the iappserversoap interface, in The soapmidas unit:
IAppServerSOAP = interface(IInvokable) ['{C99F4735-D6D2-495C-8CA2-E53E5A439E61}'] function SAS_ApplyUpdates(...): OleVariant; stdcall; function SAS_GetRecords(...): OleVariant; stdcall; function SAS_DataRequest(...): OleVariant; stdcall; function SAS_GetProviderNames: TWideStringDynArray; stdcall; function SAS_GetParams(...): OleVariant; stdcall; function SAS_RowRequest(...): OleVariant; stdcall; procedure SAS_Execute(...); stdcall; end;
Those who are familiar with the software development kit have read this code and can immediately find that it is very similar to the iappserver interface, but in the iappserver, the methods all start with AS _, And here start with SAS. Now that an iappserver interface is available, why does Borland need to add such an iappserversoap interface in update 2? I have also read some soap code before patching 2. At that time, the SOAP server data module was derived from iappserver, although iappserver was not derived from iinvokable (according to the requirements of Delphi 6, all soap interfaces must be derived from the iinvokable Interface), but in fact, iinvokable is derived directly from the iinterface, which is exactly the same as the iinterface, and iinterface is actually the ancestor interface of all com interfaces -- iunknown, iappserver is derived from the idispatch interface (a main interface of COM for automation, and its ancestor is also iunknown). Therefore, it is not necessary to directly use iappserver.
There is a comment before the iappserversoap interface definition to explain that iappserversoap replaces the safecall type method call in iappserver with the stdcall type method call, in order to implement the iappserver function in environments that do not support safecall. This is why iappserversoap appears.
It is much better to understand this. All the SOAP server data modules are derived from tsoapdatamodule and are defined in the soapdm unit. The following code is provided:
{ IAppServerSOAP } function SAS_ApplyUpdates(...): OleVariant; virtual; stdcall; function SAS_GetRecords(...): OleVariant; virtual; stdcall; function SAS_DataRequest(...): OleVariant; virtual; stdcall; function SAS_GetProviderNames: TWideStringDynArray; virtual; stdcall; function SAS_GetParams(...): OleVariant; virtual; stdcall; function SAS_RowRequest(...): OleVariant; virtual; stdcall; procedure SAS_Execute(...); virtual; stdcall;
Here is the implementation of the iappserversoap interface. Since all the SOAP server data modules are derived from tsoapdatamodule, the implementation class of the iappserversoap interface must have been implemented, but have you registered it? The following code is available in our SOAP server data module unit svrdmsoap:
procedure TSoapDemo3DMCreateInstance(out obj: TObject);begin obj := TSoapDemo3DM.Create(nil);end;initialization InvRegistry.RegisterInvokableClass(TSoapDemo3DM, TSoapDemo3DMCreateInstance);
Apparently, it has already been registered, but why is it wrong? Let's take a look at the wsdl of the isoapdemo3dm interface ...... Why is there only as_xxx? No sas_xxx? In the past, the server only exported the iappserver interface, and did not export the iappserversoap interface. This is the problem!
Let's take a look at the svrdmsoap unit:
ISoapDemo3DM = interface(IAppServer) ['{4F618288-9F81-4090-81EF-4ACE0BF6D0BE}'] end; TSoapDemo3DM = class(TSoapDataModule, ISoapDemo3DM, IAppServer)
Originally, isoapdemo3dm was derived from the iappserver interface. Obviously, this is a bug in the SOAP server data module wizard. It still generates the SOAP server data module using the iappserver interface method. It is easy to understand the problem. Change the two iappservers in the above Code to iappserversoap and re-compile the code. Let's take a look at the client program. Everything is normal. The WSDL of isoapdemo3dm correctly exports sas_xxx, especially hhttp: // localhost: 1024/demo3.wadsoapdemo3 can also see the standard WebService page of Delphi 6.02.
So far, this bug has been completely resolved. In addition, it should be noted that this problem does not exist in C ++ Builder 6.
[Mental Studio] apr.23-02 |