SOAP, dotNET, datasets, Object reference not set to an instance ofan object - XML SOAP
This is a discussion on SOAP, dotNET, datasets, Object reference not set to an instance ofan object - XML SOAP ; Hi All, please help..
Ok I've given up. Lets hope someone can help me out.
I'm trying to write a web service using dot NET and C#.
I've used xsd.exe to create my dataset from a .xsd file. I've then
...
-
SOAP, dotNET, datasets, Object reference not set to an instance ofan object
Hi All, please help..
Ok I've given up. Lets hope someone can help me out.
I'm trying to write a web service using dot NET and C#.
I've used xsd.exe to create my dataset from a .xsd file. I've then
created a web-service method which passed this dataset as a parameter.
However when I try to access this dataset as an object I get
System.NullReferenceException: Object reference not set to an instance
of an object.
at WsPie.SearchOrderSend(SearchOrderSendType SearchOrderSend) in
d:\Inetpub\wwwroot\pie-x.com\http.dev\ws\searches-test.asmx:line 163
I've written most of the code for the web service manually. I believe
I'm missing something really simple, but I just don't know what.
I'm trying to get
public string SearchOrderSend
working
I've used
public string Time
as a test method which works fine, and I can pass simple string
parameters ok. It's just when I start using complex datasets that I have
issues.
I hope this makes sense, please let me know if you need more information.
Thanks
Pritchie
==== ==== ==== ==== ==== ==== ==== ====
==== ==== ==== ==== ==== ==== ==== ====
==== ==== ==== ==== ==== ==== ==== ====
START - searches-test.asmx, My web service page
---- ---- ---- ---- ---- ---- ---- ----
<%@ WebService Language="C#" Class="WsMySite" %>
/* NOTE for telnet SOAP functions, for Content-Length: use word's
space+char count + line count + 2
*/
/*-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---70
*/
// Minimum namespaces required for webservices
using System;
using System.Web.Services; // required for WebService classes
using System.Xml.Serialization; // required for XmlAttribute()
// Other namespaces
using System.Data;
//using System.Runtime.Remoting.Metadata;
using System.Web.Services.Protocols;
using System.Xml;
/*-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---70
START Data Sets
*/
using System.Xml.Serialization;
//
// This source code was auto-generated by xsd, Version=2.0.50727.42.
//
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.oscre.org/ns/Searches/Draft-V2")]
[System.Xml.Serialization.XmlRootAttribute("SearchOrderSend",
Namespace="http://www.oscre.org/ns/Searches/Draft-V2", IsNullable=false)]
public partial class SearchOrderSendType {
private Q1HeaderType headerField = new Q1HeaderType();
private Q1AuthenticationType authenticationField = new
Q1AuthenticationType();
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public Q1HeaderType Header {
get { return this.headerField; }
set { this.headerField = value; }
}
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public Q1AuthenticationType Authentication {
get { return this.authenticationField; }
set { this.authenticationField = value; }
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.oscre.org/ns/Searches/Draft-V2")]
public partial class Q1HeaderType {
private Q1TextType versionField;
private Q1TextType modeField;
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public Q1TextType Version {
get { return this.versionField; }
set { this.versionField = value; }
}
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public Q1TextType Mode {
get { return this.modeField; }
set { this.modeField = value; }
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.oscre.org/ns/Searches/Draft-V2")]
public partial class Q1AuthenticationType {
private Q1TextType authenticationKeyField;
private Q1TextType usernameField;
private Q1TextType passwordField;
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public Q1TextType AuthenticationKey {
get { return this.authenticationKeyField; }
set { this.authenticationKeyField = value; }
}
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public Q1TextType Username {
get { return this.usernameField; }
set { this.usernameField = value; }
}
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public Q1TextType Password {
get { return this.passwordField; }
set { this.passwordField = value; }
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.oscre.org/ns/Searches/Draft-V2")]
public partial class Q1TextType {
private string valueField;
[System.Xml.Serialization.XmlTextAttribute()]
public string Value {
get { return this.valueField; }
set { this.valueField = value; }
}
}
/*-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---70
END Data Sets
*/
[ WebService(Namespace="http://mysite.com.ni.dev/ws")
]
public class WsPie: WebService
{
//Inherits System.web.ui.page
/* test time function */
[ WebMethod
( Description="Returns the time as stored on the Server"
,EnableSession=false
)
]
public string Time()
{
return Context.Timestamp.TimeOfDay.ToString();
}
/* Test method for SearchOrderSend */
[ WebMethod
( Description="SearchOrderSend, Request case searches"
,EnableSession=false
),
System.Web.Services.Protocols.SoapDocumentMethodAttribute(ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)
]
public string SearchOrderSend(SearchOrderSendType SearchOrderSend)
{
string strData = "";
Q1HeaderType objHeader = SearchOrderSend.Header;
strData = objHeader.Version.Value;
return "Data: " + strData;
}
}
==== ==== ==== ==== ==== ==== ==== ====
END - searches-test.asmx
==== ==== ==== ==== ==== ==== ==== ====
==== ==== ==== ==== ==== ==== ==== ====
==== ==== ==== ==== ==== ==== ==== ====
START - SearchOrderSend-dev.soap, My SOAP Envelope sent to
searches-test.asmx web service
---- ---- ---- ---- ---- ---- ---- ----
POST /ws/searches-test.asmx HTTP/1.1
Host: mysite.com.ni.dev
Content-Type: text/xml; charset=utf-8
Content-Length: 572
SOAPAction: "http://mysite.com.ni.dev/ws/SearchOrderSend"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<SearchOrderSend xmlns="http://mysite.com.ni.dev/ws">
<Header>
<Version>
2</Version>
<Mode>
TEST</Mode>
</Header>
<Authentication>
<Username>
TestUsername</Username>
<Password>
TestUsernamePw</Password>
</Authentication>
</SearchOrderSend>
</soap:Body>
</soap:Envelope>
==== ==== ==== ==== ==== ==== ==== ====
END - My SOAP Envelope
---- ---- ---- ---- ---- ---- ---- ----
==== ==== ==== ==== ==== ==== ==== ====
==== ==== ==== ==== ==== ==== ==== ====
==== ==== ==== ==== ==== ==== ==== ====
Feedback from the web service via netcat
---- ---- ---- ---- ---- ---- ---- ----
$ nc MySite.com.ni.dev 80 < SearchOrderSend-dev.soap
HTTP/1.1 500 Internal Server Error
Date: Thu, 24 May 2007 10:30:07 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Content-Length: 702
<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/env
elope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLS
chema"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>System.Web.Services.Pro
tocols.SoapException: Server was unable to process request. --->
System.NullReferenceException: Object reference not set to an instance
of an object.
at WsMySite.SearchOrderSend(SearchOrderSendType SearchOrderSend) in
d:\Inetpub\wwwroot\MySite.com\http.dev\ws\searches-test.asmx:line 163
--- End of inner exception stack trace ---</faultstring><detail
/></soap:Fault></soap:Body>
</soap:Envelope>
-
Re: SOAP, dotNET, datasets, Object reference not set to an instance of an object
"Pritchie" <info-2007_RemoveThis_@thebigbunker.com> wrote in message
news:20i5i.4778$rQ4.2234@newsfe1-win.ntli.net...
> Hi All, please help..
>
> Ok I've given up. Lets hope someone can help me out.
>
> I'm trying to write a web service using dot NET and C#.
>
> I've used xsd.exe to create my dataset from a .xsd file. I've then
> created a web-service method which passed this dataset as a parameter.
>
> However when I try to access this dataset as an object I get
>
> System.NullReferenceException: Object reference not set to an instance of
> an object.
NullReferenceException usually means what it says: you tried to dereference
a data item containing null. So the questions are: which data item are you
trying to dereference, and why is it null?
In the case of web services, the answers are frequently "I'm trying to
dereference an input parameter to my web method", and "because there's a
mismatch between the XML namespace that the server is expecting the elements
to be in, and the XML namespace being sent by the client". If your server is
expecting to receive something in namespace http://example.org, and you send
it something in http://example.org/myExample, then the web service will
receive null, because you didn't actually send it anything.
--
John Saunders [MVP]
-
Re: SOAP, dotNET, datasets, Object reference not set to an instanceof an object
Hi All,
Well I've now been able to get back to this.
And I've located the problem to be with regards to the XmlRootAttribute
namespace (as hinted by John). The namespace for the XmlRootAttribute
needs to be identical for both the dataset of the web method and the
SOAP envelope. As I'd played around with the code so much (it was a
mess) I decided to start again, and in doing so it worked first time. So
I then tried breaking it.
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.oscre.org/ns/Searches/Draft-V2")]
[System.Xml.Serialization.XmlRootAttribute("SearchOrderSend",
Namespace="http://www.oscre.org/ns/Searches/Draft-V2", IsNullable=false)]
public partial class SearchOrderSendType {
private Q1HeaderType headerField = new Q1HeaderType();
private Q1AuthenticationType authenticationField = new
Q1AuthenticationType();
... code removed ...
}
AND
<soap:Body>
<SearchOrderSend xmlns="http://www.oscre.org/ns/Searches/Draft-V2">
<Header xmlns="">
<Version>
2</Version>
<Mode>
TEST</Mode>
</Header>
... code removed ...
</SearchOrderSend>
</soap:Body>
IF either "http://www.oscre.org/ns/Searches/Draft-V2" in
<SearchOrderSend xmlns="http://www.oscre.org/ns/Searches/Draft-V2">
OR
[System.Xml.Serialization.XmlRootAttribute("SearchOrderSend",
Namespace="http://www.oscre.org/ns/Searches/Draft-V2", IsNullable=false)]
are different you get the error message
System.NullReferenceException: Object reference not set to an instance
of an object.
Thanks John for your help with this.
Pritchie
John Saunders [MVP] wrote:
> "Pritchie" <info-2007_RemoveThis_@thebigbunker.com> wrote in message
> news:20i5i.4778$rQ4.2234@newsfe1-win.ntli.net...
>> Hi All, please help..
>>
>> Ok I've given up. Lets hope someone can help me out.
>>
>> I'm trying to write a web service using dot NET and C#.
>>
>> I've used xsd.exe to create my dataset from a .xsd file. I've then
>> created a web-service method which passed this dataset as a parameter.
>>
>> However when I try to access this dataset as an object I get
>>
>> System.NullReferenceException: Object reference not set to an instance of
>> an object.
>
> NullReferenceException usually means what it says: you tried to dereference
> a data item containing null. So the questions are: which data item are you
> trying to dereference, and why is it null?
>
> In the case of web services, the answers are frequently "I'm trying to
> dereference an input parameter to my web method", and "because there's a
> mismatch between the XML namespace that the server is expecting the elements
> to be in, and the XML namespace being sent by the client". If your server is
> expecting to receive something in namespace http://example.org, and you send
> it something in http://example.org/myExample, then the web service will
> receive null, because you didn't actually send it anything.
-
Re: SOAP, dotNET, datasets, Object reference not set to an instanceof an object
Also the children of SearchOrderSend need to have a blank namespace set.
Why this is I'm sure, maybe someone out there can explain it.
However this works
<soap:Body>
<SearchOrderSend xmlns="http://www.oscre.org/ns/Searches/Draft-V2">
<Header xmlns="">
<Version>2.0</Version>
<Mode>TEST</Mode>
</Header>
<Authentication xmlns="">
<AuthenticationKey />
<Username>PiePropertyServices</Username>
<Password>Password123</Password>
</Authentication>
<SearchOrder xmlns="">
<SearchOrderDate>2007-04-17</SearchOrderDate>
<ProductQuantityNumeric>2</ProductQuantityNumeric>
<TotalPriceAmount currencyID="GBP">153.95</TotalPriceAmount>
</SearchOrder>
</SearchOrderSend>
</soap:Body>
But remove the
xmlns=""
so
<SearchOrder xmlns="">
becomes
<SearchOrder>
and you get NullReferenceException.
<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/env
elope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLS
chema"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>System.Web.Services.Pro
tocols.SoapException: Server was unable to process request. --->
System.NullReferenceException: Object reference not set to an instance
of an object.
So removing xmlns="" changes the namespace of that element.
"...
An empty value for xmlns makes the mapping treat unprefixed element type
names as local names (which is the default behaviour in the absence of
xmlns attributes).
...."
http://www.jclark.com/xml/xmlns.htm
"...
The system has inserted an xmlns="" namespace declaration because you
have asked for the <exportTimeStamp> element to go in the null
namespace.
...."
http://www.biglist.com/lists/xsl-lis.../msg00986.html
Thanks
Pritchie
John Saunders [MVP] wrote:
> "Pritchie" <info-2007_RemoveThis_@thebigbunker.com> wrote in message
> news:20i5i.4778$rQ4.2234@newsfe1-win.ntli.net...
>> Hi All, please help..
>>
>> Ok I've given up. Lets hope someone can help me out.
>>
>> I'm trying to write a web service using dot NET and C#.
>>
>> I've used xsd.exe to create my dataset from a .xsd file. I've then
>> created a web-service method which passed this dataset as a parameter.
>>
>> However when I try to access this dataset as an object I get
>>
>> System.NullReferenceException: Object reference not set to an instance of
>> an object.
>
> NullReferenceException usually means what it says: you tried to dereference
> a data item containing null. So the questions are: which data item are you
> trying to dereference, and why is it null?
>
> In the case of web services, the answers are frequently "I'm trying to
> dereference an input parameter to my web method", and "because there's a
> mismatch between the XML namespace that the server is expecting the elements
> to be in, and the XML namespace being sent by the client". If your server is
> expecting to receive something in namespace http://example.org, and you send
> it something in http://example.org/myExample, then the web service will
> receive null, because you didn't actually send it anything.
-
Re: SOAP, dotNET, datasets, Object reference not set to an instance of an object
On May 24, 10:28 pm, "John Saunders [MVP]" <john.saunders at
trizetto.com> wrote:
> "Pritchie" <info-2007_RemoveTh...@thebigbunker.com> wrote in message
>
> news:20i5i.4778$rQ4.2234@newsfe1-win.ntli.net...
>
> > Hi All, please help..
>
> > Ok I've given up. Lets hope someone can help me out.
>
> > I'm trying to write a web service using dot NET and C#.
>
> > I've used xsd.exe to create my dataset from a .xsd file. I've then
> > created a web-service method which passed this dataset as a parameter.
>
> > However when I try to access this dataset as an object I get
>
> > System.NullReferenceException: Object reference not set to an instance of
> > an object.
>
> NullReferenceException usually means what it says: you tried to dereference
> a data item containing null. So the questions are: which data item are you
> trying to dereference, and why is it null?
>
> In the case of web services, the answers are frequently "I'm trying to
> dereference an input parameter to my web method", and "because there's a
> mismatch between the XML namespace that the server is expecting the elements
> to be in, and the XML namespace being sent by the client". If your server is
> expecting to receive something in namespacehttp://example.org, and you send
> it something inhttp://example.org/myExample, then the web service will
> receive null, because you didn't actually send it anything.
> --
> John Saunders [MVP]
hi friend
when i got this Exception
ihave reinitilzed the class i am using u can try with this
regards
santosh
-
Re: SOAP, dotNET, datasets, Object reference not set to an instance of an object
<santosh.gornal> wrote in message
news:1184215755.989280.271420@d55g2000hsg.googlegroups.com...
> On May 24, 10:28 pm, "John Saunders [MVP]" <john.saunders at
> trizetto.com> wrote:
>> "Pritchie" <info-2007_RemoveTh...@thebigbunker.com> wrote in message
>>
>> news:20i5i.4778$rQ4.2234@newsfe1-win.ntli.net...
>>
>> > Hi All, please help..
>>
>> > Ok I've given up. Lets hope someone can help me out.
>>
>> > I'm trying to write a web service using dot NET and C#.
>>
>> > I've used xsd.exe to create my dataset from a .xsd file. I've then
>> > created a web-service method which passed this dataset as a parameter.
>>
>> > However when I try to access this dataset as an object I get
>>
>> > System.NullReferenceException: Object reference not set to an instance
>> > of
>> > an object.
>>
>> NullReferenceException usually means what it says: you tried to
>> dereference
>> a data item containing null. So the questions are: which data item are
>> you
>> trying to dereference, and why is it null?
>>
>> In the case of web services, the answers are frequently "I'm trying to
>> dereference an input parameter to my web method", and "because there's a
>> mismatch between the XML namespace that the server is expecting the
>> elements
>> to be in, and the XML namespace being sent by the client". If your server
>> is
>> expecting to receive something in namespacehttp://example.org, and you
>> send
>> it something inhttp://example.org/myExample, then the web service will
>> receive null, because you didn't actually send it anything.
>> --
>> John Saunders [MVP]
>
> hi friend
> when i got this Exception
> ihave reinitilzed the class i am using u can try with this
I do not understand your question. Please provide more detail.
--
John Saunders [MVP]
Similar Threads
-
By Application Development in forum CSharp
Replies: 3
Last Post: 09-26-2007, 09:06 PM
-
By Application Development in forum DOTNET
Replies: 1
Last Post: 08-09-2007, 10:00 AM
-
By Application Development in forum DOTNET
Replies: 1
Last Post: 03-27-2007, 06:49 AM
-
By Application Development in forum XML SOAP
Replies: 0
Last Post: 02-16-2006, 12:08 PM
-
By Application Development in forum DOTNET
Replies: 1
Last Post: 07-29-2004, 07:10 AM