473,386 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Web-Services with a Collection of a custom object

Hi there,

I'm trying to consume a web-service that is supposed to return a
collection of a custom object. The web-service was not created with C# or
VS.net. It was created with IBM VisualAge Smalltalk 6. I haven't had
problems consuming other web-services but c# seems to choke with
"Collection" return types. The collection (or array) is supposed to
contain three instances of a custom object called PsmWsResult, which has
two variable members: code, and description.
If you'd like to try to see an example of this problem you can add the
following web-reference to your project:

http://216.18.68.93:9999/CollectionWsInterface.wsdl
(The browser window will say that there are no functions found, but they
are there)
After adding the web-reference and renaming it "CollectionsTest", I
created a plain vanilla windows app and inserted the following into the
form load event:

CollectionsTest.CollectionWsInterface ws =
new CollectionsTest.CollectionWsInterface();

//PsmWsCollection seems to be the return object
//which is supposed to be a collection.
CollectionsTest.PsmWsCollection wsCollection;

wsCollection = ws.getCollection();

At this point, the debugger halts execution here:

"CollectionsTest\Reference.cs"

-------------------------------
[System.Web.Services.Protocols.SoapRpcMethodAttribu te
("http://www.CollectionWsInterface.com/CollectionWsInterface-
interface/getCollectio" +
"n", RequestNamespace="urn:CollectionWsInterface",
ResponseNamespace="urn:CollectionWsInterface")]
[return: System.Xml.Serialization.SoapElementAttribute("out MsgText")]
public PsmWsCollection getCollection() {

//debugger breaks at the following line!

object[] results = this.Invoke("getCollection", new object[0]);
return ((PsmWsCollection)(results[0]));
}
-------------------------------

The first lines of the stack trace:

-------------------------------
Unhandled Exception: System.InvalidOperationException: There is an error
in XML document (16, 14). ---> System.InvalidCastException: Cannot assign
object of type WindowsApplication3.CollectionsTest.PsmWsResult to an
object of type WindowsApplication3.CollectionsTest.PsmWsResult[].
at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationReader1.Rea
d1_PsmWsCollection()
-------------------------------

Which leads me to believe that the collection is being returned as an
array itself. I'm stuck at this point, how do I cast the return type to
be an array of itself??

If I try the following:

wsCollection = (CollectionsTest.PsmWsCollection[])ws.getCollection();

I get a "Cannot convert type" error when compiling.
I tried invoking the getCollection function using "Web Service Studio"
and it chokes on it as well!
If anyone has any clue on what I should do to correct this, I'd
appreciate it!

Thanks!

Jorge
Nov 23 '05 #1
4 4484
I gave it a try a few times, the WSDL is somehow using RPC/encoded which
is the heart of the problem. Look in at the return SoapEnvelope I could
at leat get to the raw Xml and the only way i could come out with is
using Xml, and XPath to rebuild the object
to get to the raw messages all you need to do is override on method in
the proxy
protected override WebResponse GetWebResponse(WebRequest request)
{
WebResponse r = base.GetWebResponse (request);
XmlDocument doc = new XmlDocument();
doc.Load(r.GetResponseStream());
Console.WriteLine("------------------------\r\n{0}",
doc.DocumentElement.OuterXml);
return r;
}

------------ RETURN ENVELOPE ----------------->

ResponseCode: 200 (Ok)
Content-Type:text/xml
Content-Length:1116

<?xml version="1.0" encoding="utf-16"?>
<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:mrwi="http://www.CollectionWsInterface.com/CollectionWsInterface/xsd"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<cwi:getCollectionOut xmlns:cwi="urn:CollectionWsInterface">
<outMsgText href="#id1" />
</cwi:getCollectionOut>
<multiRef1 xsi:type="mrwi:PsmWsCollection" id="id1">
<element xsi:type="mrwi:PsmWsResult">
<code xsi:type="xsd:string">1</code>
<description xsi:type="xsd:string">1</description>
</element>
<element xsi:type="mrwi:PsmWsResult">
<code xsi:type="xsd:string">2</code>
<description xsi:type="xsd:string">2</description>
</element>
<element xsi:type="mrwi:PsmWsResult">
<code xsi:type="xsd:string">3</code>
<description xsi:type="xsd:string">3</description>
</element>
</multiRef1>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Regards
Erymuzuan Mustapa

hellrazor wrote:
Hi there,

I'm trying to consume a web-service that is supposed to return a
collection of a custom object. The web-service was not created with C# or
VS.net. It was created with IBM VisualAge Smalltalk 6. I haven't had
problems consuming other web-services but c# seems to choke with
"Collection" return types. The collection (or array) is supposed to
contain three instances of a custom object called PsmWsResult, which has
two variable members: code, and description.
If you'd like to try to see an example of this problem you can add the
following web-reference to your project:

http://216.18.68.93:9999/CollectionWsInterface.wsdl
(The browser window will say that there are no functions found, but they
are there)
After adding the web-reference and renaming it "CollectionsTest", I
created a plain vanilla windows app and inserted the following into the
form load event:

CollectionsTest.CollectionWsInterface ws =
new CollectionsTest.CollectionWsInterface();

//PsmWsCollection seems to be the return object
//which is supposed to be a collection.
CollectionsTest.PsmWsCollection wsCollection;

wsCollection = ws.getCollection();

At this point, the debugger halts execution here:

"CollectionsTest\Reference.cs"

-------------------------------
[System.Web.Services.Protocols.SoapRpcMethodAttribu te
("http://www.CollectionWsInterface.com/CollectionWsInterface-
interface/getCollectio" +
"n", RequestNamespace="urn:CollectionWsInterface",
ResponseNamespace="urn:CollectionWsInterface")]
[return: System.Xml.Serialization.SoapElementAttribute("out MsgText")]
public PsmWsCollection getCollection() {

//debugger breaks at the following line!

object[] results = this.Invoke("getCollection", new object[0]);
return ((PsmWsCollection)(results[0]));
}
-------------------------------

The first lines of the stack trace:

-------------------------------
Unhandled Exception: System.InvalidOperationException: There is an error
in XML document (16, 14). ---> System.InvalidCastException: Cannot assign
object of type WindowsApplication3.CollectionsTest.PsmWsResult to an
object of type WindowsApplication3.CollectionsTest.PsmWsResult[].
at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationReader1.Rea
d1_PsmWsCollection()
-------------------------------

Which leads me to believe that the collection is being returned as an
array itself. I'm stuck at this point, how do I cast the return type to
be an array of itself??

If I try the following:

wsCollection = (CollectionsTest.PsmWsCollection[])ws.getCollection();

I get a "Cannot convert type" error when compiling.
I tried invoking the getCollection function using "Web Service Studio"
and it chokes on it as well!
If anyone has any clue on what I should do to correct this, I'd
appreciate it!

Thanks!

Jorge

Nov 23 '05 #2
erymuzuan <er*******@yahoo.com> wrote in
news:es**************@TK2MSFTNGP15.phx.gbl:
I gave it a try a few times, the WSDL is somehow using RPC/encoded
which is the heart of the problem. Look in at the return SoapEnvelope
I could at leat get to the raw Xml and the only way i could come out
with is using Xml, and XPath to rebuild the object
to get to the raw messages all you need to do is override on method in
the proxy
protected override WebResponse GetWebResponse(WebRequest request)
{
WebResponse r = base.GetWebResponse (request);
XmlDocument doc = new XmlDocument();
doc.Load(r.GetResponseStream());
Console.WriteLine("------------------------\r\n{0}",
doc.DocumentElement.OuterXml);
return r;
}


Hi,

thanks for your reply.

Would you be able to tell me exactly where I should stick this code?

Would it be within my form1.cs code, or do I need to create another class?

Thank you!
Nov 23 '05 #3
in your proxy class, and you can exposed the XMLDocument as property if
you wish.

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

//
// This source code was auto-generated by wsdl, Version=1.1.4322.2032.
//
using System.Diagnostics;
using System.Xml.Serialization;
using System;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Web.Services;
/// <remarks/>
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("c ode")]
[System.Web.Services.WebServiceBindingAttribute(Nam e="CollectionWsInterfaceBinding",
Namespace="http://www.CollectionWsInterface.com/CollectionWsInterface-interface")]
public class CollectionWsInterface :
System.Web.Services.Protocols.SoapHttpClientProtoc ol {

private XMLDocument m_doc;
// - create the XMlDocumnet property
public XmlDocument GetColllection()
{
// invoke the getCollection -> ignore the return values
this.Collection();

if(null != m_doc)
return m_doc;

throw new Exception("Document is not properly initialized");

}

protected override WebResponse GetWebResponse(WebRequest request)
{
WebResponse r = base.GetWebResponse (request);
m_doc = new XmlDocument();
doc.Load(r.GetResponseStream());
return r;
}
/// <remarks/>
public CollectionWsInterface() {
this.Url = "http://216.18.68.93:7374/SstWSServlet";
}

/// <remarks/>

[System.Web.Services.Protocols.SoapRpcMethodAttribu te("http://www.CollectionWsInterface.com/CollectionWsInterface-interface/getCollectio"
+
"n", RequestNamespace="urn:CollectionWsInterface",
ResponseNamespace="urn:CollectionWsInterface")]
[return: System.Xml.Serialization.SoapElementAttribute("out MsgText")]
public PsmWsCollection getCollection() {
object[] results = this.Invoke("getCollection", new object[0]);
return ((PsmWsCollection)(results[0]));
}

/// <remarks/>
public System.IAsyncResult BegingetCollection(System.AsyncCallback
callback, object asyncState) {
return this.BeginInvoke("getCollection", new object[0],
callback, asyncState);
}

/// <remarks/>
public PsmWsCollection EndgetCollection(System.IAsyncResult
asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((PsmWsCollection)(results[0]));
}
}

/// <remarks/>
[System.Xml.Serialization.SoapTypeAttribute("PsmWsC ollection",
"http://www.CollectionWsInterface.com/CollectionWsInterface/xsd")]
public class PsmWsCollection {

/// <remarks/>
public PsmWsResult[] element;
}

/// <remarks/>
[System.Xml.Serialization.SoapTypeAttribute("PsmWsR esult",
"http://www.CollectionWsInterface.com/CollectionWsInterface/xsd")]
public class PsmWsResult {

/// <remarks/>
public string code;

/// <remarks/>
public string description;
}
Nov 23 '05 #4
erymuzuan,

Thanks a lot for your help, please see my comments below

erymuzuan <er*******@yahoo.com> wrote in
news:OC**************@TK2MSFTNGP09.phx.gbl:

<snip>

/// <remarks/>
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("c ode")]
[System.Web.Services.WebServiceBindingAttribute(Nam e="CollectionWsInter
faceBinding",
Namespace="http://www.CollectionWsInterface.com/CollectionWsInterface-i
nterface")] public class CollectionWsInterface :
System.Web.Services.Protocols.SoapHttpClientProtoc ol {

private XMLDocument m_doc;
// - create the XMlDocumnet property
public XmlDocument GetColllection()
{
// invoke the getCollection -> ignore the return values
this.getCollection();

if(null != m_doc)
return m_doc;

throw new Exception("Document is not properly initialized");

}
Where is the above function called from? Should I call GetCollection()
instead of getCollection() where I call the web-service function?

example:
CollectionsTest.CollectionWsInterface ws = new
CollectionsTest.CollectionWsInterface();
wsCollection = ws.GetCollection();

or should I be calling the GetCollection() function from elsewhere
protected override WebResponse GetWebResponse(WebRequest request)
{
WebResponse r = base.GetWebResponse (request);
m_doc = new XmlDocument();
doc.Load(r.GetResponseStream());
return r;
}


I can write the return envelope to the console (using the example in your
previous post) but it's one long string with no breaking lines.

Soon after the GetWebResponse function executes, it crashes at the
function:

public PsmWsCollection getCollection() {
// - crashes at the below line!
object[] results = this.Invoke("getCollection", new object[0]);
return ((PsmWsCollection)(results[0]));
}
The stack trace says:

Unhandled Exception: System.Xml.XmlException: The root element is
missing.
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlReader.MoveToContent()
at System.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadResponse
(SoapClientMessage message, WebResponse response, Stream responseStream,
Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtoc ol.Invoke(String
methodName, Object[] parameters)

Thanks for your help!
Nov 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mike | last post by:
Sites using thumbnail preview for world wide web file navigation and searching. Below are list of sites that are either researching or providing thumbnail preview images for online web...
6
by: Billy Jacobs | last post by:
I have a website which has both secure and non-secure pages. I want to uses forms authentication. How do I accomplish this? Originally I had my web.config file in the root with Forms...
0
by: Bill Burwell | last post by:
I am converting a VB6 WebClass application to VB.Net. Used the VB upgrade tool to do the conversion - and it left me a lot of little code things to do. Did those code things and got my app to...
25
by: John Morgan | last post by:
Though I have designed and implemented a number of large reasonably well received web sites I do not consider myself a graphics designer I am now for the first time going to work with a ...
8
by: John Baker | last post by:
Hi: I am URGENTLY in need of some book or web site OR tool that will help me integrate a relatively simple access application into a web page or pages. This is a time recording system (by...
4
by: Trond A. S. Andersen | last post by:
Hi, all! I'm trying to use the System.Web.Mail. "package" combinded with System.Web.Mail.SmtpMail in order to send MS Excel spreadsheets attached to mail messages. However, sending one single...
16
by: C. Woody Butler | last post by:
I have a strange problem with a website and a web service. They're both on the same server, running Windows server 2003. The website is set up as the default website for the server. I've got...
2
by: Lucas Fletcher | last post by:
Hello, I was wondering how I can reference assemblies from web.config files residing in subdirectories without having to create a new project for each web.config-containing subdirectory? I...
2
by: Jeff | last post by:
Hey asp.net 2.0 My asp.net 2.0 project has got a assembly load problem: Some of my web.config settings: <membership defaultProvider="AH_MembershipProvider" userIsOnlineTimeWindow="15">
7
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I did my MCAD sometime ago in 1.1, using the 305 manual. I've since moved up to VS 2005. I've created perhaps a half dozen Dot Net 2.0 web applications. (Click on the Create Project link within...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.