PRB: "SoapServer.SoapInvoke failed" Error with ASP Listeners (297131)



The information in this article applies to:

  • Microsoft SOAP Toolkit 2.0
  • Microsoft Active Server Pages

This article was previously published under Q297131

SYMPTOMS

With the Active Server Pages (ASP) files that are generated by WSDL/WSML Generator that ships with Microsoft SOAP Toolkit Version 2, when you try to run multiple SoapServer object instances on the same Web application, you may receive the following error message from the SOAP clients:
The request could not be processed due to a problem in the server. Please contact the system admistrator. SoapServer.SoapInvoke failed. Object required.

CAUSE

When you use the WSDL/WSML Generator tool to create ASP pages for ASP Listener projects, the generated ASP code allows only one SoapServer object instance per Web application (virtual folder) to run on a Web server at any point in time.

RESOLUTION

To resolve this problem, use one of the following methods:
  • Modify the ASP pages that are generated by WSDL/WSML Generator, or create new ASP pages based on your requirements.
  • Use the ISAPI Listener instead of the ASP Listener.

STATUS

This behavior is by design.

MORE INFORMATION

The following is an example of a typical ASP page that is created by the WSDL/WSML Generator.
<%@ LANGUAGE=VBScript %>
<%
Option Explicit
On Error Resume Next
Response.ContentType = "text/xml"
Dim SoapServer
If Not Application("SoapServerInitialized") Then
  Application.Lock
  If Not Application("SoapServerInitialized") Then
    Dim WSDLFilePath
    Dim WSMLFilePath
    WSDLFilePath = Server.MapPath("MyService.wsdl")
    WSMLFilePath = Server.MapPath("MyService.wsml")
    Set SoapServer = Server.CreateObject("MSSOAP.SoapServer")
    If Err Then SendFault "Cannot create SoapServer object. " & Err.Description
    SoapServer.Init WSDLFilePath, WSMLFilePath
    If Err Then SendFault "SoapServer.Init failed. " & Err.Description
    Set Application("MyServiceServer") = SoapServer
    Application("SoapServerInitialized") = True
  End If
  Application.UnLock
End If
Set SoapServer = Application("MyServiceServer")
SoapServer.SoapInvoke Request, Response, ""
If Err Then SendFault "SoapServer.SoapInvoke failed. " & Err.Description
Sub SendFault(ByVal LogMessage)
  Dim Serializer
  On Error Resume Next
  ' "URI Query" logging must be enabled for AppendToLog to work.
  Response.AppendToLog " SOAP ERROR: " & LogMessage
  Set Serializer = Server.CreateObject("MSSOAP.SoapSerializer")
  If Err Then
    Response.AppendToLog "Could not create SoapSerializer object. " & Err.Description
    Response.Status = "500 Internal Server Error"
  Else
    Serializer.Init Response
    If Err Then
      Response.AppendToLog "SoapSerializer.Init failed. " & Err.Description
      Response.Status = "500 Internal Server Error"
    Else
      Serializer.startEnvelope
      Serializer.startBody
      Serializer.startFault "Server", "The request could not be processed due to a problem in the server. Please contact the system admistrator. " & LogMessage
      Serializer.endFault
      Serializer.endBody
      Serializer.endEnvelope
      If Err Then
        Response.AppendToLog "SoapSerializer failed. " & Err.Description
        Response.Status = "500 Internal Server Error"
      End If
    End If
  End If
  Response.End
End Sub
%>
				
Note that this code sets the SoapServerInitialized application-level variable during the first run to True after creating the SoapServer object. Because this section of code is common for all the generated ASP pages for all SoapServer objects, subsequent calls to those ASP pages do not initialize the other SoapServer objects, resulting in the failure.

You can modify the generated ASP pages to resolve this problem. For example, you can use multiple application-level initialization variables such as SoapServer1Initialized, SoapServer2Initialized, and so forth to run multiple SoapServer objects on the same Web application. The modified code may resemble the following:
<%@ LANGUAGE=VBScript %>
<%
Option Explicit
On Error Resume Next
Response.ContentType = "text/xml"
Dim SoapServer
If Not Application("MyService_1_Initialized") Then
  Application.Lock
  If Not Application("MyService_1_Initialized") Then
    Dim WSDLFilePath
    Dim WSMLFilePath
    WSDLFilePath = Server.MapPath("MyService_1.wsdl")
    WSMLFilePath = Server.MapPath("MyService_1.wsml")
    Set SoapServer = Server.CreateObject("MSSOAP.SoapServer")
    If Err Then SendFault "Cannot create SoapServer object. " & Err.Description
    SoapServer.Init WSDLFilePath, WSMLFilePath
    If Err Then SendFault "SoapServer.Init failed. " & Err.Description
    Set Application("MyService_1_Server") = SoapServer
    Application("MyService_1_Initialized") = True
  End If
  Application.UnLock
End If
Set SoapServer = Application("MyService_1_Server")
SoapServer.SoapInvoke Request, Response, ""
If Err Then SendFault "SoapServer.SoapInvoke failed. " & Err.Description
Sub SendFault(ByVal LogMessage)
  Dim Serializer
  On Error Resume Next
  ' "URI Query" logging must be enabled for AppendToLog to work.
  Response.AppendToLog " SOAP ERROR: " & LogMessage
  Set Serializer = Server.CreateObject("MSSOAP.SoapSerializer")
  If Err Then
    Response.AppendToLog "Could not create SoapSerializer object. " & Err.Description
    Response.Status = "500 Internal Server Error"
  Else
    Serializer.Init Response
    If Err Then
      Response.AppendToLog "SoapSerializer.Init failed. " & Err.Description
      Response.Status = "500 Internal Server Error"
    Else
      Serializer.startEnvelope
      Serializer.startBody
      Serializer.startFault "Server", "The request could not be processed due to a problem in the server. Please contact the system admistrator. " & LogMessage
      Serializer.endFault
      Serializer.endBody
      Serializer.endEnvelope
      If Err Then
        Response.AppendToLog "SoapSerializer failed. " & Err.Description
        Response.Status = "500 Internal Server Error"
      End If
    End If
  End If
  Response.End
End Sub
%>
				
This design allows the SoapServer objects to be cached on the Web server. You can also create the SoapServer objects and intialization variables at page-level scope instead of caching at application-level scope.

Modification Type:MajorLast Reviewed:10/28/2003
Keywords:kbprb KB297131