Forum » Programiranje » c# Web Service NullReferenceException
c# Web Service NullReferenceException
smejko ::
Živijo!
Imam spodnjo metodo, in mi vrača Exception:
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at TestWS.createReq(CreateReq CreateReq) in c:\TestWS\TestWS.asmx:line 109
--- End of inner exception stack trace --
Morda kdo ve v čem je težava?
public partial class CreateReq
{
public string input;
}
public partial class CreateResp
{
public Rezultat Rezultat;
}
public partial class Rezultat
{
public int vrednost;
public string opis;
}
[WebMethod(Description = "CreateRequest", CacheDuration = 0, BufferResponse = false)]
[SoapDocumentMethodAttribute(ParameterStyle = SoapParameterStyle.Bare)]
[return: XmlElement("CreateResp")]
public CreateResp createReq(CreateReq CreateReq)
{
CreateResp res = new CreateResp();
CreateReq req = createReq;
res.Rezultat.vrednost = 0;
res.Rezultat.opis = "OK";
return res;
}
Imam spodnjo metodo, in mi vrača Exception:
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at TestWS.createReq(CreateReq CreateReq) in c:\TestWS\TestWS.asmx:line 109
--- End of inner exception stack trace --
Morda kdo ve v čem je težava?
public partial class CreateReq
{
public string input;
}
public partial class CreateResp
{
public Rezultat Rezultat;
}
public partial class Rezultat
{
public int vrednost;
public string opis;
}
[WebMethod(Description = "CreateRequest", CacheDuration = 0, BufferResponse = false)]
[SoapDocumentMethodAttribute(ParameterStyle = SoapParameterStyle.Bare)]
[return: XmlElement("CreateResp")]
public CreateResp createReq(CreateReq CreateReq)
{
CreateResp res = new CreateResp();
CreateReq req = createReq;
res.Rezultat.vrednost = 0;
res.Rezultat.opis = "OK";
return res;
}
darkolord ::
Rezultat je null.
Ali pa to narediš v konstruktorju CreateResp.
res.Rezultat = new Rezultat(); res.Rezultat.vrednost = 0; res.Rezultat.opis = "OK";
Ali pa to narediš v konstruktorju CreateResp.
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | C# težavaOddelek: Programiranje | 3757 (2603) | mladec |
» | ASP.NET + C# vprašanjeOddelek: Programiranje | 2796 (1810) | Morenov |
» | Avtomatično prepoznati POST spremenljivkeOddelek: Programiranje | 1582 (1375) | AnonimkeOP |
» | [C#] WebResponse vrne error 404Oddelek: Programiranje | 1028 (989) | darkolord |
» | HTTP POSTOddelek: Programiranje | 1761 (1537) | kopernik |