0

I have a web service in SAP and I have to make a C# client to the web service. I create the client but I receive an error from C#. Error is this :

Object reference not set to an instance of an object.

My source for client is this:

Uri uri = new Uri("http://address");
var address = new EndpointAddress(uri, EndpointIdentity.CreateSpnIdentity("teste"));
ServiceReference2.ZWS_PEP_ENVIO_MRZClient wsclient = new ServiceReference2.ZWS_PEP_ENVIO_MRZClient();
//  wsclient.Endpoint.Binding.Scheme;
wsclient.ClientCredentials.UserName.UserName = "user_name";
wsclient.ClientCredentials.UserName.Password = "password";
wsclient.Endpoint.Address = address;
wsclient.Open();


ServiceReference2.ZwsPepEnvioMrz request = new ServiceReference2.ZwsPepEnvioMrz();
request.Descricao = descricaoField;
request.Mrz1 = mrz1Field;
request.Mrz2 = mrz2Field;
request.Numeroprocesso = numeroprocessoField;
request.Sn = snField;
request.Statusdatapreparation = statusdatapreparationField;
request.Versaodocumento = versaodocumentoField;

wsclient.ZwsPepEnvioMrz(request);
ServiceReference2.ZwsPepEnvioMrzResponse1 response = new ServiceReference2.ZwsPepEnvioMrzResponse1();
Resultado = response.ZwsPepEnvioMrzResponse.ToString();
textBox1.Text = Resultado;


wsclient.Close();

And the program terminates at

Resultado= response.ZwsPepEnvioMrzResponse.ToString()

Any ideas why?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48

1 Answers1

0

this won't work:

wsclient.ZwsPepEnvioMrz(request);
ServiceReference2.ZwsPepEnvioMrzResponse1 response = new  ServiceReference2.ZwsPepEnvioMrzResponse1();

you can't create a new response object yourself and expect it to contain any data. The response object should be the result from your web service call. I can't check this as the types are specific to your web service, but if the ws method ZwsPepEnviroMrz returns an object of type ServiceReference2.ZwsPepEnvioMrzResponse1 you should try this:

ServiceReference2.ZwsPepEnvioMrzResponse1 response = wsclient.ZwsPepEnvioMrz(request);

now the response variable should contain some data and this

Resultado = response.ZwsPepEnvioMrzResponse.ToString();

should work.

Dirk Trilsbeek
  • 5,873
  • 2
  • 25
  • 23