472,968 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

System.InvalidCastException: Unable to cast object of type 'System.Xml.XmlDocument' to type 'System.String'


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

[System.Web.Services.WebServiceBindingAttribute(Nam e = "ValidateBinding",
Namespace = "http://example.org/Avtentikacija")]
public class MyWebService : SoapHttpClientProtocol
{
[System.Web.Services.Protocols.SoapDocumentMethodAt tribute("", Use =
System.Web.Services.Description.SoapBindingUse.Lit eral, ParameterStyle =
System.Web.Services.Protocols.SoapParameterStyle.B are)]
public XmlDocument validate(string url,
[System.Xml.Serialization.XmlElementAttribute(Names pace =
"http://www.example.org/PodpisaniDokument")] XmlDocument xmlDocument)
{
this.Url = url;
object[] results = null;
try
{
// ERROR occur at this line :(
results = this.Invoke("validate", 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.PreserveWhitespace = true;
xmlDocument.Load("C:\\request.xml");

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

And I got this error message:

System.InvalidOperationException: There was an error generating the XML
document. ---> System.InvalidCastException: Unable to cast object of type
'System.Xml.XmlDocument' to type 'System.String'.
at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriterMyWebService.Write1_validate(Obj ect[]
p)
at
Microsoft.Xml.Serialization.GeneratedAssembly.Arra yOfObjectSerializer.Serialize(Object
objectToSerialize, XmlSerializationWriter writer)
at System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter,
Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String
id)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter,
Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String
id)
at System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter,
Object o, XmlSerializerNamespaces namespaces, String encodingStyle)
at
System.Web.Services.Protocols.SoapHttpClientProtoc ol.Serialize(SoapClientMessage
message)
at System.Web.Services.Protocols.SoapHttpClientProtoc ol.Invoke(String
methodName, Object[] parameters)
at MyWeb.MyWebService.validate(String url, XmlDocument xmlDocument) in
C:\Documents and Settings\I\My Documents\Visual Studio
2005\Projects\MyWeb\MyWeb\Form1.cs:line 152

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

When I change this line:

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

into this:

results = this.Invoke("validate", new object[] {
xmlDocument.OuterXml.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********@microsoft.com> wrote in message
news:Kj*******************@news.siol.net...

When I change this line:

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

into this:

results = this.Invoke("validate", new object[] {
xmlDocument.OuterXml.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
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...
4
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...
0
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) { ...
3
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'. ...
4
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
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...
2
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...
8
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...
1
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...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.