473,902 Members | 4,620 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.InvalidC astException: Unable to cast object of type 'System.Xml.Xml Document' to type 'System.String'


I'm writing webervice client using .Net 2.0. I have this class:

[System.Web.Serv ices.WebService BindingAttribut e(Name = "ValidateBindin g",
Namespace = "http://example.org/Avtentikacija")]
public class MyWebService : SoapHttpClientP rotocol
{
[System.Web.Serv ices.Protocols. SoapDocumentMet hodAttribute("" , Use =
System.Web.Serv ices.Descriptio n.SoapBindingUs e.Literal, ParameterStyle =
System.Web.Serv ices.Protocols. SoapParameterSt yle.Bare)]
public XmlDocument validate(string url,
[System.Xml.Seri alization.XmlEl ementAttribute( Namespace =
"http://www.example.org/PodpisaniDokume nt")] XmlDocument xmlDocument)
{
this.Url = url;
object[] results = null;
try
{
// ERROR occur at this line :(
results = this.Invoke("va lidate", new object[] { xmlDocument });
}
catch (Exception ex)
{
MessageBox.Show (ex.ToString()) ;
return null;
}
return ((XmlDocument)( results[0]));
}
}

and I call it like this:

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Pre serveWhitespace = true;
xmlDocument.Loa d("C:\\request. xml");

MyWebService web = new MyWebService();
xmlDocument =
web.validate("h ttp://localhost:8080/MyWeb/services/Avtentikacija",
xmlDocument);
if (xmlDocument != null)
xmlDocument.Sav e("C:\\response .xml");

And I got this error message:

System.InvalidO perationExcepti on: There was an error generating the XML
document. ---> System.InvalidC astException: Unable to cast object of type
'System.Xml.Xml Document' to type 'System.String' .
at
Microsoft.Xml.S erialization.Ge neratedAssembly .XmlSerializati onWriterMyWebSe rvice.Write1_va lidate(Object[]
p)
at
Microsoft.Xml.S erialization.Ge neratedAssembly .ArrayOfObjectS erializer.Seria lize(Object
objectToSeriali ze, XmlSerializatio nWriter writer)
at System.Xml.Seri alization.XmlSe rializer.Serial ize(XmlWriter xmlWriter,
Object o, XmlSerializerNa mespaces namespaces, String encodingStyle, String
id)
--- End of inner exception stack trace ---
at System.Xml.Seri alization.XmlSe rializer.Serial ize(XmlWriter xmlWriter,
Object o, XmlSerializerNa mespaces namespaces, String encodingStyle, String
id)
at System.Xml.Seri alization.XmlSe rializer.Serial ize(XmlWriter xmlWriter,
Object o, XmlSerializerNa mespaces namespaces, String encodingStyle)
at
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.Seriali ze(SoapClientMe ssage
message)
at System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.Invoke( String
methodName, Object[] parameters)
at MyWeb.MyWebServ ice.validate(St ring url, XmlDocument xmlDocument) in
C:\Documents and Settings\I\My Documents\Visua l Studio
2005\Projects\M yWeb\MyWeb\Form 1.cs:line 152

Why? :(
Apr 13 '06 #1
2 13614

When I change this line:

results = this.Invoke("va lidate", new object[] { xmlDocument });

into this:

results = this.Invoke("va lidate", new object[] {
xmlDocument.Out erXml.ToString( ) });

it (almost) works. The problem is that it wraps my XML document into <url
http://www.example.org/Avtentikacija"> my xml here...</url> inside
<soap:body>, like this:

<soap:Body>
<url xmlns="http://sigen.si/Avtentikacija">
MyXML here...
</url>
</soap:Body>

Why? I don't want this! Webservice that I call can't parse it. It doesn't
expects <url></url> :(
Apr 13 '06 #2
We need full service description, generated client proxy and request.xml to
figure out what is going wrong here. Could you please provde this
information?

Thanks,

Zafar

"John Smith" <jo********@mic rosoft.com> wrote in message
news:Kj******** ***********@new s.siol.net...

When I change this line:

results = this.Invoke("va lidate", new object[] { xmlDocument });

into this:

results = this.Invoke("va lidate", new object[] {
xmlDocument.Out erXml.ToString( ) });

it (almost) works. The problem is that it wraps my XML document into <url
http://www.example.org/Avtentikacija"> my xml here...</url> inside
<soap:body>, like this:

<soap:Body>
<url xmlns="http://sigen.si/Avtentikacija">
MyXML here...
</url>
</soap:Body>

Why? I don't want this! Webservice that I call can't parse it. It doesn't
expects <url></url> :(

Apr 14 '06 #3

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

Similar topics

0
5634
by: Fidias Gil de Montes | last post by:
In a Distributed Windows application, I receive the following message when the client calls the server: ************** Exception Text ************** System.InvalidCastException: Unable to cast object of type System.__ComObject to type System.Data.DataSet. Server stack trace: at servidor.IclaseSvr.prueba2(DataSet ds) at
4
2670
by: DOTNET | last post by:
Hi, Anybody help me regarding this error: I am assigning the values to the session variables when the button is clicked and passing these session variables to the next page and when I am printing these session variables they are printing. After that I am assigning these things in hidden object and in the form submit action I am receiving these hidden values like the following:
0
4901
by: Luis Esteban Valencia | last post by:
Hello I have this error when I submit the page with the following code. I had never see this kind of errors. Thanks private void btnsubmit_Click(object sender, System.EventArgs e) { string requestLocation = "http://estacion15/HTTPSender/BTSHTTPReceive.dll";
3
13023
by: Imran Aziz | last post by:
Hello All, I am getting the following error on our production server, and I dont get the same error on the development box. Unable to cast object of type 'System.Byte' to type 'System.String'. here is the code that I used to create a table and then add columns to it later, later I populate the rows in the table.
4
3886
by: John Smith | last post by:
How can I allow someone to cast my C# class into System.String? Is it possible in C#? In C++ I used "operator" keyword to mark C++ member function.
1
5170
by: Ratz | last post by:
Hello everyone! I'm new to this Forum! I've spent about 56 hours trying to solve a .NET VB Runtime error while Using a program.Ive contacted the developer of the program and he could not figure out why i'm getting these errors! SO i have come here for the Help from the GURUS! here is one message that pops up! See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box. **************...
2
2819
by: Jim S | last post by:
I have a .net framework 2.0 client (Pocket PC) and a .net 2.0 webservice that communicate on the same LAN. The Pocket PC has no problem consuming strings returned from the web service methoeds but I’m unable to receive and a custom object. The error occurs when the PocketPC app casts a returned object (WebServiceServer.objectA) from the webservice to pocketPC.ObjectA (results in InvalidCastExeption). ObjectA is a simple class and is...
8
4280
by: Gamma | last post by:
I'm trying to inherit subclass from System.Diagnostics.Process, but whenever I cast a "Process" object to it's subclass, I encounter an exception "System.InvalidCastException" ("Specified cast is not valid"). How do I fix it ? using System.Diagnostics; .. .. class NewProcess: Process {
1
3964
by: miller.brettm | last post by:
Hi, I'm working with an ActiveX serial component that fires an event when data is received. I need to continue to use this component because it contains the ability to do Xmodem1k an d XmodemCRC comms The RX even fires and passes an Object (Type: Object) parameter. When looking @ the Locals window it shows the Type as: Object { byte } <Code>
0
9997
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9845
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10872
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10981
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9675
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7205
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5893
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4307
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3323
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.