Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / March 2007

Tip: Looking for answers? Try searching our database.

Error consuming a web service in axis

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeremy Chapman - 12 Mar 2007 21:33 GMT
I've writtin a very simple web service in axis which returns an array of
classes.

I consume it in a .net app.  When receiving the response, my .net app
generates an error "Cannot assign object of type System.Object[] to an
object of type PersonWS.WorkGroupData[].".

I've included the wsdl of the consumed axis web service, the
request/responses of the web service by the .net app and the exception and
stack trace.  Hoping someone can tell me what I'm doing wrong here.

**** Class I'm trying to serialize:
package ca.comp.openview;

public class WorkGroupData  implements java.io.Serializable
{
static final long serialVersionUID = 1;

public String Name;
public String SearchCode;

public WorkGroupData()
{

}

public WorkGroupData(String strName, String strSearchCode)
{
 Name = strName;
 SearchCode = strSearchCode;
}

}

**** WSDL:
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:tns1="http://openview.comp.ca"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:impl="http://dc1serv306:8080/axis/PersonWS.jws"
xmlns:intf="http://dc1serv306:8080/axis/PersonWS.jws"
targetNamespace="http://dc1serv306:8080/axis/PersonWS.jws"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
 <wsdl:types>
   <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://openview.comp.ca">
     <xsd:import namespace="http://dc1serv306:8080/axis/PersonWS.jws" />
     <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
     <xsd:lexType name="WorkGroupData">
       <xsd:sequence>
         <xsd:element name="Name" nillable="true" type="xsd:string" />
         <xsd:element name="SearchCode" nillable="true" type="xsd:string"
/>
       </xsd:sequence>
     </xsd:lexType>
   </xsd:schema>
   <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://dc1serv306:8080/axis/PersonWS.jws">
     <xsd:import namespace="http://openview.comp.ca" />
     <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
     <xsd:lexType name="ArrayOf_tns1_WorkGroupData">
       <xsd:lexContent mixed="false">
         <xsd:restriction base="soapenc:Array">
           <xsd:attribute wsdl:arrayType="tns1:WorkGroupData[]"
ref="soapenc:arrayType" />
         </xsd:restriction>
       </xsd:lexContent>
     </xsd:lexType>
   </xsd:schema>
 </wsdl:types>
 <wsdl:message name="ListWorkGroupsRequest">
   <wsdl:part name="strPerson" type="xsd:string" />
 </wsdl:message>
 <wsdl:message name="ListWorkGroupsResponse">
   <wsdl:part name="ListWorkGroupsReturn"
type="intf:ArrayOf_tns1_WorkGroupData" />
 </wsdl:message>
 <wsdl:portType name="PersonWS">
   <wsdl:operation name="ListWorkGroups" parameterOrder="strPerson">
     <wsdl:input name="ListWorkGroupsRequest"
message="intf:ListWorkGroupsRequest" />
     <wsdl:output name="ListWorkGroupsResponse"
message="intf:ListWorkGroupsResponse" />
   </wsdl:operation>
 </wsdl:portType>
 <wsdl:binding name="PersonWSSoapBinding" type="intf:PersonWS">
   <wsdlsoap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="rpc" />
   <wsdl:operation name="ListWorkGroups">
     <wsdlsoap:operation soapAction="" />
     <wsdl:input name="ListWorkGroupsRequest">
       <wsdlsoap:body use="encoded" namespace="http://DefaultNamespace"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
     </wsdl:input>
     <wsdl:output name="ListWorkGroupsResponse">
       <wsdlsoap:body use="encoded"
namespace="http://dc1serv306:8080/axis/PersonWS.jws"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
     </wsdl:output>
   </wsdl:operation>
 </wsdl:binding>
 <wsdl:service name="PersonWSService">
   <wsdl:port name="PersonWS" binding="intf:PersonWSSoapBinding">
     <wsdlsoap:address location="http://dc1serv306:8080/axis/PersonWS.jws"
/>
   </wsdl:port>
 </wsdl:service>
</wsdl:definitions>

**** Web service request:
POST /axis/PersonWS.jws HTTP/1.1
User-Agent: Mozilla/4.0 (atible; MSIE 6.0; MS Web Services Client Protocol
2.0.50727.42)
VsDebuggerCausalityData:
uIDPo0CmVGk8IFRKtnoM+dd/g1UAAAAABhYLv0zewUCAHJEZp0AP92+xiiG8VKREqmQwwAAIXQ0ACAAA
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
Host: localhost:8080
Content-Length: 613
Expect: 100-continue

<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="http://dc1serv306:8080/axis/PersonWS.jws"
xmlns:types="http://dc1serv306:8080/axis/PersonWS.jws/encodedTypes"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><q1:ListWorkGroups
xmlns:q1="http://DefaultNamespace"><strPerson
xsi:type="xsd:string">chaj17</strPerson></q1:ListWorkGroups></soap:Body></soap:Envelope>

**** Web service response:
HTTP/1.1 100 Continue

HTTP/1.1 200 OK
Set-Cookie: JSESSIONID=EA7F4F1C1E1390AA0294E6B087F5D3EF; Path=/axis
Content-Type: text/xml;charset=utf-8
Transfer-Encoding: chunked
Date: Mon, 12 Mar 2007 20:24:28 GMT
Server: Apache-Coyote/1.1

231
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><ns1:ListWorkGroupsResponse
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns1="http://DefaultNamespace"><ListWorkGroupsReturn
soapenc:arrayType="xsd:anyType[0]" xsi:type="soapenc:Array"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"/></ns1:ListWorkGroupsResponse></soape
nv:Body></soapenv:Envelope
>
0

**** .Net Exception
Exception information:
Type   : InvalidOperationException
Source : System.Xml
Link   :
Message: There is an error in XML document (1, 501).

Trace  :
  at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader
xmlReader, String encodingStyle, XmlDeserializationEvents events)
  at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader
xmlReader, String encodingStyle)
  at
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage
message, WebResponse response, Stream responseStream, Boolean asyncCall)
  at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String
methodName, Object[] parameters)
  at PersonWS.PersonWSService.ListWorkGroups(String strPerson) in
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET
Files\quickservicecall\821bd8ec\e1741ba7\App_WebReferences.s_47-nlz.0.cs:line
48
  at _Default.ListWorkGroups(String strMnemonic) in
e:\Develop\2.0\Projects\Service Desk\Quick Service Call\Web
Applications\QuickServiceCall\Default.aspx.cs:line 30
  at _Default.Page_Load(Object sender, EventArgs e) in
e:\Develop\2.0\Projects\Service Desk\Quick Service Call\Web
Applications\QuickServiceCall\Default.aspx.cs:line 45
  at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object
o, Object t, EventArgs e)
  at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
EventArgs e)
  at System.Web.UI.Control.OnLoad(EventArgs e)
  at System.Web.UI.Control.LoadRecursive()
  at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Inner exception (1):
Exception information:
Type   : InvalidCastException
Source : xnnfxwfg
Link   :
Message: Cannot assign object of type System.Object[] to an object of type
PersonWS.WorkGroupData[].

Trace  :
  at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderPersonWSService.Read3_ListWorkGroupsResponse()
  at
Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer1.Deserialize(XmlSerializationReader
reader)
  at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader
xmlReader, String encodingStyle, XmlDeserializationEvents events)
John Saunders - 12 Mar 2007 23:18 GMT
> I've writtin a very simple web service in axis which returns an array of
> classes.
[quoted text clipped - 6 lines]
> request/responses of the web service by the .net app and the exception and
> stack trace.  Hoping someone can tell me what I'm doing wrong here.

You should try a few things. First, please enclose the .NET proxy code that
is causing the error.

Second, try consuming an array of int to see if the problem is "array" or
"of class".

John
Jeremy Chapman - 13 Mar 2007 00:27 GMT
I added a method that returns an array of int and I can call that method
fine from my .net app.

As for the proxy code, this is an asp.net 2.0 app I'm consuming from, so
most proxy code is done somehow behind the scenes which I can't seem to get
to decided to consume it from a .net windows app, which generates the same
error, and does let me see the proxy code, so I included that below.

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.42
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

//
// This source code was auto-generated by Microsoft.VSDesigner, Version
2.0.50727.42.
//
#pragma warning disable 1591

namespace WindowsApplication1.PersonWS {
   using System.Diagnostics;
   using System.Web.Services;
   using System.ComponentModel;
   using System.Web.Services.Protocols;
   using System;
   using System.Xml.Serialization;

   /// <remarks/>
   [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services",
"2.0.50727.42")]
   [System.Diagnostics.DebuggerStepThroughAttribute()]
   [System.ComponentModel.DesignerCategoryAttribute("code")]
   [System.Web.Services.WebServiceBindingAttribute(Name="PersonWSSoapBinding",
Namespace="http://dc1serv306:8080/axis/PersonWS.jws")]
   [System.Xml.Serialization.SoapIncludeAttribute(typeof(WorkGroupData))]
   public partial class PersonWSService :
System.Web.Services.Protocols.SoapHttpClientProtocol {

       private System.Threading.SendOrPostCallback TestOperationCompleted;

       private System.Threading.SendOrPostCallback
ListWorkGroupsOperationCompleted;

       private bool useDefaultCredentialsSetExplicitly;

       /// <remarks/>
       public PersonWSService() {
           this.Url =
global::WindowsApplication1.Properties.Settings.Default.WindowsApplication1_PersonWS_PersonWSService;
           if ((this.IsLocalFileSystemWebService(this.Url) == true)) {
               this.UseDefaultCredentials = true;
               this.useDefaultCredentialsSetExplicitly = false;
           }
           else {
               this.useDefaultCredentialsSetExplicitly = true;
           }
       }

       public new string Url {
           get {
               return base.Url;
           }
           set {
               if ((((this.IsLocalFileSystemWebService(base.Url) == true)
                           && (this.useDefaultCredentialsSetExplicitly ==
false))
                           && (this.IsLocalFileSystemWebService(value) ==
false))) {
                   base.UseDefaultCredentials = false;
               }
               base.Url = value;
           }
       }

       public new bool UseDefaultCredentials {
           get {
               return base.UseDefaultCredentials;
           }
           set {
               base.UseDefaultCredentials = value;
               this.useDefaultCredentialsSetExplicitly = true;
           }
       }

       /// <remarks/>
       public event TestCompletedEventHandler TestCompleted;

       /// <remarks/>
       public event ListWorkGroupsCompletedEventHandler
ListWorkGroupsCompleted;

       /// <remarks/>
       [System.Web.Services.Protocols.SoapRpcMethodAttribute("",
RequestNamespace="http://DefaultNamespace",
ResponseNamespace="http://dc1serv306:8080/axis/PersonWS.jws")]
       [return:
System.Xml.Serialization.SoapElementAttribute("TestReturn")]
       public int[] Test(string strPerson) {
           object[] results = this.Invoke("Test", new object[] {
                       strPerson});
           return ((int[])(results[0]));
       }

       /// <remarks/>
       public void TestAsync(string strPerson) {
           this.TestAsync(strPerson, null);
       }

       /// <remarks/>
       public void TestAsync(string strPerson, object userState) {
           if ((this.TestOperationCompleted == null)) {
               this.TestOperationCompleted = new
System.Threading.SendOrPostCallback(this.OnTestOperationCompleted);
           }
           this.InvokeAsync("Test", new object[] {
                       strPerson}, this.TestOperationCompleted, userState);
       }

       private void OnTestOperationCompleted(object arg) {
           if ((this.TestCompleted != null)) {
               System.Web.Services.Protocols.InvokeCompletedEventArgs
invokeArgs =
((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
               this.TestCompleted(this, new
TestCompletedEventArgs(invokeArgs.Results, invokeArgs.Error,
invokeArgs.Cancelled, invokeArgs.UserState));
           }
       }

       /// <remarks/>
       [System.Web.Services.Protocols.SoapRpcMethodAttribute("",
RequestNamespace="http://DefaultNamespace",
ResponseNamespace="http://dc1serv306:8080/axis/PersonWS.jws")]
       [return:
System.Xml.Serialization.SoapElementAttribute("ListWorkGroupsReturn")]
       public WorkGroupData[] ListWorkGroups(string strPerson) {
           object[] results = this.Invoke("ListWorkGroups", new object[] {
                       strPerson});
           return ((WorkGroupData[])(results[0]));
       }

       /// <remarks/>
       public void ListWorkGroupsAsync(string strPerson) {
           this.ListWorkGroupsAsync(strPerson, null);
       }

       /// <remarks/>
       public void ListWorkGroupsAsync(string strPerson, object userState)
{
           if ((this.ListWorkGroupsOperationCompleted == null)) {
               this.ListWorkGroupsOperationCompleted = new
System.Threading.SendOrPostCallback(this.OnListWorkGroupsOperationCompleted);
           }
           this.InvokeAsync("ListWorkGroups", new object[] {
                       strPerson}, this.ListWorkGroupsOperationCompleted,
userState);
       }

       private void OnListWorkGroupsOperationCompleted(object arg) {
           if ((this.ListWorkGroupsCompleted != null)) {
               System.Web.Services.Protocols.InvokeCompletedEventArgs
invokeArgs =
((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
               this.ListWorkGroupsCompleted(this, new
ListWorkGroupsCompletedEventArgs(invokeArgs.Results, invokeArgs.Error,
invokeArgs.Cancelled, invokeArgs.UserState));
           }
       }

       /// <remarks/>
       public new void CancelAsync(object userState) {
           base.CancelAsync(userState);
       }

       private bool IsLocalFileSystemWebService(string url) {
           if (((url == null)
                       || (url == string.Empty))) {
               return false;
           }
           System.Uri wsUri = new System.Uri(url);
           if (((wsUri.Port >= 1024)
                       && (string.Compare(wsUri.Host, "localHost",
System.StringComparison.OrdinalIgnoreCase) == 0))) {
               return true;
           }
           return false;
       }
   }

   /// <remarks/>
   [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml",
"2.0.50727.42")]
   [System.SerializableAttribute()]
   [System.Diagnostics.DebuggerStepThroughAttribute()]
   [System.ComponentModel.DesignerCategoryAttribute("code")]
   [System.Xml.Serialization.SoapTypeAttribute(Namespace="http://openview.comp.ca")]
   public partial class WorkGroupData {

       private string nameField;

       private string searchCodeField;

       /// <remarks/>
       [System.Xml.Serialization.SoapElementAttribute(IsNullable=true)]
       public string Name {
           get {
               return this.nameField;
           }
           set {
               this.nameField = value;
           }
       }

       /// <remarks/>
       [System.Xml.Serialization.SoapElementAttribute(IsNullable=true)]
       public string SearchCode {
           get {
               return this.searchCodeField;
           }
           set {
               this.searchCodeField = value;
           }
       }
   }

   /// <remarks/>
   [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services",
"2.0.50727.42")]
   public delegate void TestCompletedEventHandler(object sender,
TestCompletedEventArgs e);

   /// <remarks/>
   [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services",
"2.0.50727.42")]
   [System.Diagnostics.DebuggerStepThroughAttribute()]
   [System.ComponentModel.DesignerCategoryAttribute("code")]
   public partial class TestCompletedEventArgs :
System.ComponentModel.AsyncCompletedEventArgs {

       private object[] results;

       internal TestCompletedEventArgs(object[] results, System.Exception
exception, bool cancelled, object userState) :
               base(exception, cancelled, userState) {
           this.results = results;
       }

       /// <remarks/>
       public int[] Result {
           get {
               this.RaiseExceptionIfNecessary();
               return ((int[])(this.results[0]));
           }
       }
   }

   /// <remarks/>
   [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services",
"2.0.50727.42")]
   public delegate void ListWorkGroupsCompletedEventHandler(object sender,
ListWorkGroupsCompletedEventArgs e);

   /// <remarks/>
   [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services",
"2.0.50727.42")]
   [System.Diagnostics.DebuggerStepThroughAttribute()]
   [System.ComponentModel.DesignerCategoryAttribute("code")]
   public partial class ListWorkGroupsCompletedEventArgs :
System.ComponentModel.AsyncCompletedEventArgs {

       private object[] results;

       internal ListWorkGroupsCompletedEventArgs(object[] results,
System.Exception exception, bool cancelled, object userState) :
               base(exception, cancelled, userState) {
           this.results = results;
       }

       /// <remarks/>
       public WorkGroupData[] Result {
           get {
               this.RaiseExceptionIfNecessary();
               return ((WorkGroupData[])(this.results[0]));
           }
       }
   }
}

>> I've writtin a very simple web service in axis which returns an array of
>> classes.
[quoted text clipped - 14 lines]
>
> John
John Saunders - 13 Mar 2007 00:48 GMT
>I added a method that returns an array of int and I can call that method
>fine from my .net app.
[quoted text clipped - 3 lines]
> get to decided to consume it from a .net windows app, which generates the
> same error, and does let me see the proxy code, so I included that below.

I didn't see anything blatantly wrong with the proxy code. Are you able to
find the line of code that the exception references?

John

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.