Trying to get data from wsdl using c#












0















I have this c# code where i am trying to get data from a wsdl in visual studio .
The code is okay but when i try to get the data to written on notepad it just shows an empty space :



WindowsService1.ServiceReference1.GetModifiedBookingsOperationResponse getModbkgsResp;
using (var proxy = new WindowsService1.ServiceReference1.InventoryServiceClient())
{
int noofBookings = 1;
getModbkgsResp = proxy.GetModifiedBookings(getModBkgsReq);
WindowsService1.ServiceReference1.Booking bookings = new WindowsService1.ServiceReference1.Booking[noofBookings];
getModbkgsResp.Bookings = new WindowsService1.ServiceReference1.Booking[noofBookings];
getModbkgsResp.Bookings = bookings;
if (getModbkgsResp.Bookings != null)
{
for (int i = 0; i < bookings.Length; i++)
{

Booking bk = new WindowsService1.ServiceReference1.Booking();
getModbkgsResp.Bookings[i] = bk;
if (bk != null )
{
bookingSource = bk.BookingSource;
if (bk.BookingId == Bookingcode)
{
this.WriteToFile("Booking Source =" + bookingSource + "");
}
else
{
this.WriteToFile("Sorry could not find your source of booking");

}
}
else
{
this.WriteToFile("Looks like source is null " );

}
}
}
else
{
this.WriteToFile("ERROR: Booking details not returned from GetModifiedBookings! " +StartDate);
}
}









share|improve this question

























  • Have you tried setting a breakpoint and stepping through the code? Do you think it could be important to show the definition of WriteToFile? If the question is related to something failing to be written to a file it seems to me that it would be important to see the actual code that does the writing to the file.

    – Jason Boyd
    Jan 2 at 22:15













  • You seem to be calling GetModifiedBookings but then overwriting the response's Bookings array with a new one. What is the logic behind that? Yes, they will all be blank when you do that.

    – John Wu
    Jan 2 at 22:16











  • Also, have you confirmed that bookings.Length is greater than 0?

    – Jason Boyd
    Jan 2 at 22:18











  • @JasonBoyd below is the code for the writetoFile: private void WriteToFile(string text) { string path = "C:\ServiceLog.txt"; using (StreamWriter writer = new StreamWriter(path, true)) { writer.WriteLine(string.Format(text, DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt"))); writer.Close(); } }

    – Luke Luvevou
    Jan 2 at 22:23













  • @JohnWu okay will try to ammend that and advice about the result

    – Luke Luvevou
    Jan 2 at 22:29
















0















I have this c# code where i am trying to get data from a wsdl in visual studio .
The code is okay but when i try to get the data to written on notepad it just shows an empty space :



WindowsService1.ServiceReference1.GetModifiedBookingsOperationResponse getModbkgsResp;
using (var proxy = new WindowsService1.ServiceReference1.InventoryServiceClient())
{
int noofBookings = 1;
getModbkgsResp = proxy.GetModifiedBookings(getModBkgsReq);
WindowsService1.ServiceReference1.Booking bookings = new WindowsService1.ServiceReference1.Booking[noofBookings];
getModbkgsResp.Bookings = new WindowsService1.ServiceReference1.Booking[noofBookings];
getModbkgsResp.Bookings = bookings;
if (getModbkgsResp.Bookings != null)
{
for (int i = 0; i < bookings.Length; i++)
{

Booking bk = new WindowsService1.ServiceReference1.Booking();
getModbkgsResp.Bookings[i] = bk;
if (bk != null )
{
bookingSource = bk.BookingSource;
if (bk.BookingId == Bookingcode)
{
this.WriteToFile("Booking Source =" + bookingSource + "");
}
else
{
this.WriteToFile("Sorry could not find your source of booking");

}
}
else
{
this.WriteToFile("Looks like source is null " );

}
}
}
else
{
this.WriteToFile("ERROR: Booking details not returned from GetModifiedBookings! " +StartDate);
}
}









share|improve this question

























  • Have you tried setting a breakpoint and stepping through the code? Do you think it could be important to show the definition of WriteToFile? If the question is related to something failing to be written to a file it seems to me that it would be important to see the actual code that does the writing to the file.

    – Jason Boyd
    Jan 2 at 22:15













  • You seem to be calling GetModifiedBookings but then overwriting the response's Bookings array with a new one. What is the logic behind that? Yes, they will all be blank when you do that.

    – John Wu
    Jan 2 at 22:16











  • Also, have you confirmed that bookings.Length is greater than 0?

    – Jason Boyd
    Jan 2 at 22:18











  • @JasonBoyd below is the code for the writetoFile: private void WriteToFile(string text) { string path = "C:\ServiceLog.txt"; using (StreamWriter writer = new StreamWriter(path, true)) { writer.WriteLine(string.Format(text, DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt"))); writer.Close(); } }

    – Luke Luvevou
    Jan 2 at 22:23













  • @JohnWu okay will try to ammend that and advice about the result

    – Luke Luvevou
    Jan 2 at 22:29














0












0








0








I have this c# code where i am trying to get data from a wsdl in visual studio .
The code is okay but when i try to get the data to written on notepad it just shows an empty space :



WindowsService1.ServiceReference1.GetModifiedBookingsOperationResponse getModbkgsResp;
using (var proxy = new WindowsService1.ServiceReference1.InventoryServiceClient())
{
int noofBookings = 1;
getModbkgsResp = proxy.GetModifiedBookings(getModBkgsReq);
WindowsService1.ServiceReference1.Booking bookings = new WindowsService1.ServiceReference1.Booking[noofBookings];
getModbkgsResp.Bookings = new WindowsService1.ServiceReference1.Booking[noofBookings];
getModbkgsResp.Bookings = bookings;
if (getModbkgsResp.Bookings != null)
{
for (int i = 0; i < bookings.Length; i++)
{

Booking bk = new WindowsService1.ServiceReference1.Booking();
getModbkgsResp.Bookings[i] = bk;
if (bk != null )
{
bookingSource = bk.BookingSource;
if (bk.BookingId == Bookingcode)
{
this.WriteToFile("Booking Source =" + bookingSource + "");
}
else
{
this.WriteToFile("Sorry could not find your source of booking");

}
}
else
{
this.WriteToFile("Looks like source is null " );

}
}
}
else
{
this.WriteToFile("ERROR: Booking details not returned from GetModifiedBookings! " +StartDate);
}
}









share|improve this question
















I have this c# code where i am trying to get data from a wsdl in visual studio .
The code is okay but when i try to get the data to written on notepad it just shows an empty space :



WindowsService1.ServiceReference1.GetModifiedBookingsOperationResponse getModbkgsResp;
using (var proxy = new WindowsService1.ServiceReference1.InventoryServiceClient())
{
int noofBookings = 1;
getModbkgsResp = proxy.GetModifiedBookings(getModBkgsReq);
WindowsService1.ServiceReference1.Booking bookings = new WindowsService1.ServiceReference1.Booking[noofBookings];
getModbkgsResp.Bookings = new WindowsService1.ServiceReference1.Booking[noofBookings];
getModbkgsResp.Bookings = bookings;
if (getModbkgsResp.Bookings != null)
{
for (int i = 0; i < bookings.Length; i++)
{

Booking bk = new WindowsService1.ServiceReference1.Booking();
getModbkgsResp.Bookings[i] = bk;
if (bk != null )
{
bookingSource = bk.BookingSource;
if (bk.BookingId == Bookingcode)
{
this.WriteToFile("Booking Source =" + bookingSource + "");
}
else
{
this.WriteToFile("Sorry could not find your source of booking");

}
}
else
{
this.WriteToFile("Looks like source is null " );

}
}
}
else
{
this.WriteToFile("ERROR: Booking details not returned from GetModifiedBookings! " +StartDate);
}
}






c# asp.net web-services wsdl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 22:08









Jason Boyd

4,33641938




4,33641938










asked Jan 2 at 21:54









Luke LuvevouLuke Luvevou

407




407













  • Have you tried setting a breakpoint and stepping through the code? Do you think it could be important to show the definition of WriteToFile? If the question is related to something failing to be written to a file it seems to me that it would be important to see the actual code that does the writing to the file.

    – Jason Boyd
    Jan 2 at 22:15













  • You seem to be calling GetModifiedBookings but then overwriting the response's Bookings array with a new one. What is the logic behind that? Yes, they will all be blank when you do that.

    – John Wu
    Jan 2 at 22:16











  • Also, have you confirmed that bookings.Length is greater than 0?

    – Jason Boyd
    Jan 2 at 22:18











  • @JasonBoyd below is the code for the writetoFile: private void WriteToFile(string text) { string path = "C:\ServiceLog.txt"; using (StreamWriter writer = new StreamWriter(path, true)) { writer.WriteLine(string.Format(text, DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt"))); writer.Close(); } }

    – Luke Luvevou
    Jan 2 at 22:23













  • @JohnWu okay will try to ammend that and advice about the result

    – Luke Luvevou
    Jan 2 at 22:29



















  • Have you tried setting a breakpoint and stepping through the code? Do you think it could be important to show the definition of WriteToFile? If the question is related to something failing to be written to a file it seems to me that it would be important to see the actual code that does the writing to the file.

    – Jason Boyd
    Jan 2 at 22:15













  • You seem to be calling GetModifiedBookings but then overwriting the response's Bookings array with a new one. What is the logic behind that? Yes, they will all be blank when you do that.

    – John Wu
    Jan 2 at 22:16











  • Also, have you confirmed that bookings.Length is greater than 0?

    – Jason Boyd
    Jan 2 at 22:18











  • @JasonBoyd below is the code for the writetoFile: private void WriteToFile(string text) { string path = "C:\ServiceLog.txt"; using (StreamWriter writer = new StreamWriter(path, true)) { writer.WriteLine(string.Format(text, DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt"))); writer.Close(); } }

    – Luke Luvevou
    Jan 2 at 22:23













  • @JohnWu okay will try to ammend that and advice about the result

    – Luke Luvevou
    Jan 2 at 22:29

















Have you tried setting a breakpoint and stepping through the code? Do you think it could be important to show the definition of WriteToFile? If the question is related to something failing to be written to a file it seems to me that it would be important to see the actual code that does the writing to the file.

– Jason Boyd
Jan 2 at 22:15







Have you tried setting a breakpoint and stepping through the code? Do you think it could be important to show the definition of WriteToFile? If the question is related to something failing to be written to a file it seems to me that it would be important to see the actual code that does the writing to the file.

– Jason Boyd
Jan 2 at 22:15















You seem to be calling GetModifiedBookings but then overwriting the response's Bookings array with a new one. What is the logic behind that? Yes, they will all be blank when you do that.

– John Wu
Jan 2 at 22:16





You seem to be calling GetModifiedBookings but then overwriting the response's Bookings array with a new one. What is the logic behind that? Yes, they will all be blank when you do that.

– John Wu
Jan 2 at 22:16













Also, have you confirmed that bookings.Length is greater than 0?

– Jason Boyd
Jan 2 at 22:18





Also, have you confirmed that bookings.Length is greater than 0?

– Jason Boyd
Jan 2 at 22:18













@JasonBoyd below is the code for the writetoFile: private void WriteToFile(string text) { string path = "C:\ServiceLog.txt"; using (StreamWriter writer = new StreamWriter(path, true)) { writer.WriteLine(string.Format(text, DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt"))); writer.Close(); } }

– Luke Luvevou
Jan 2 at 22:23







@JasonBoyd below is the code for the writetoFile: private void WriteToFile(string text) { string path = "C:\ServiceLog.txt"; using (StreamWriter writer = new StreamWriter(path, true)) { writer.WriteLine(string.Format(text, DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt"))); writer.Close(); } }

– Luke Luvevou
Jan 2 at 22:23















@JohnWu okay will try to ammend that and advice about the result

– Luke Luvevou
Jan 2 at 22:29





@JohnWu okay will try to ammend that and advice about the result

– Luke Luvevou
Jan 2 at 22:29












1 Answer
1






active

oldest

votes


















0














I'm not sure why you are using the new keyword to create items that should have been retrieved from the service. Naturally anything created with new will be initialized with default values and will not contain any data that was retrieved from the service.



My guess is your code should look more like this:



using (var proxy = new WindowsService1.ServiceReference1.InventoryServiceClient())
{
var response = proxy.GetModifiedBookings(getModBkgsReq);
if (response.Bookings == null)
{
this.WriteToFile("ERROR: Booking details not returned from GetModifiedBookings! " +StartDate);
return;
}
var booking = response.Bookings.SingleOrDefault( b => b.BookingId == bookingCode);
if (booking == null)
{
this.WriteToFile("Sorry could not find your source of booking");
return;
}
var bookingSource = booking.BookingSource;
this.WriteToFile("Booking Source =" + bookingSource + "");
}





share|improve this answer
























  • thanks this code works fine

    – Luke Luvevou
    Jan 2 at 23:25











  • but it seems that it keeps on returning null with the message "Sorry could not find your source of booking" how do i ensure that it returns something :

    – Luke Luvevou
    Jan 3 at 1:50













  • Got me. Could be a bug in the service, or maybe you have the wrong booking number.

    – John Wu
    Jan 3 at 2:48











  • i have even added an existing booking number and still it gives the "Sorry could not find your source of booking"

    – Luke Luvevou
    Jan 3 at 3:21











  • i have updated you code and it works i also updated the service reference as well..on visual studio.. and i able to pull bookings/data

    – Luke Luvevou
    Jan 9 at 23:50












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54013663%2ftrying-to-get-data-from-wsdl-using-c-sharp%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I'm not sure why you are using the new keyword to create items that should have been retrieved from the service. Naturally anything created with new will be initialized with default values and will not contain any data that was retrieved from the service.



My guess is your code should look more like this:



using (var proxy = new WindowsService1.ServiceReference1.InventoryServiceClient())
{
var response = proxy.GetModifiedBookings(getModBkgsReq);
if (response.Bookings == null)
{
this.WriteToFile("ERROR: Booking details not returned from GetModifiedBookings! " +StartDate);
return;
}
var booking = response.Bookings.SingleOrDefault( b => b.BookingId == bookingCode);
if (booking == null)
{
this.WriteToFile("Sorry could not find your source of booking");
return;
}
var bookingSource = booking.BookingSource;
this.WriteToFile("Booking Source =" + bookingSource + "");
}





share|improve this answer
























  • thanks this code works fine

    – Luke Luvevou
    Jan 2 at 23:25











  • but it seems that it keeps on returning null with the message "Sorry could not find your source of booking" how do i ensure that it returns something :

    – Luke Luvevou
    Jan 3 at 1:50













  • Got me. Could be a bug in the service, or maybe you have the wrong booking number.

    – John Wu
    Jan 3 at 2:48











  • i have even added an existing booking number and still it gives the "Sorry could not find your source of booking"

    – Luke Luvevou
    Jan 3 at 3:21











  • i have updated you code and it works i also updated the service reference as well..on visual studio.. and i able to pull bookings/data

    – Luke Luvevou
    Jan 9 at 23:50
















0














I'm not sure why you are using the new keyword to create items that should have been retrieved from the service. Naturally anything created with new will be initialized with default values and will not contain any data that was retrieved from the service.



My guess is your code should look more like this:



using (var proxy = new WindowsService1.ServiceReference1.InventoryServiceClient())
{
var response = proxy.GetModifiedBookings(getModBkgsReq);
if (response.Bookings == null)
{
this.WriteToFile("ERROR: Booking details not returned from GetModifiedBookings! " +StartDate);
return;
}
var booking = response.Bookings.SingleOrDefault( b => b.BookingId == bookingCode);
if (booking == null)
{
this.WriteToFile("Sorry could not find your source of booking");
return;
}
var bookingSource = booking.BookingSource;
this.WriteToFile("Booking Source =" + bookingSource + "");
}





share|improve this answer
























  • thanks this code works fine

    – Luke Luvevou
    Jan 2 at 23:25











  • but it seems that it keeps on returning null with the message "Sorry could not find your source of booking" how do i ensure that it returns something :

    – Luke Luvevou
    Jan 3 at 1:50













  • Got me. Could be a bug in the service, or maybe you have the wrong booking number.

    – John Wu
    Jan 3 at 2:48











  • i have even added an existing booking number and still it gives the "Sorry could not find your source of booking"

    – Luke Luvevou
    Jan 3 at 3:21











  • i have updated you code and it works i also updated the service reference as well..on visual studio.. and i able to pull bookings/data

    – Luke Luvevou
    Jan 9 at 23:50














0












0








0







I'm not sure why you are using the new keyword to create items that should have been retrieved from the service. Naturally anything created with new will be initialized with default values and will not contain any data that was retrieved from the service.



My guess is your code should look more like this:



using (var proxy = new WindowsService1.ServiceReference1.InventoryServiceClient())
{
var response = proxy.GetModifiedBookings(getModBkgsReq);
if (response.Bookings == null)
{
this.WriteToFile("ERROR: Booking details not returned from GetModifiedBookings! " +StartDate);
return;
}
var booking = response.Bookings.SingleOrDefault( b => b.BookingId == bookingCode);
if (booking == null)
{
this.WriteToFile("Sorry could not find your source of booking");
return;
}
var bookingSource = booking.BookingSource;
this.WriteToFile("Booking Source =" + bookingSource + "");
}





share|improve this answer













I'm not sure why you are using the new keyword to create items that should have been retrieved from the service. Naturally anything created with new will be initialized with default values and will not contain any data that was retrieved from the service.



My guess is your code should look more like this:



using (var proxy = new WindowsService1.ServiceReference1.InventoryServiceClient())
{
var response = proxy.GetModifiedBookings(getModBkgsReq);
if (response.Bookings == null)
{
this.WriteToFile("ERROR: Booking details not returned from GetModifiedBookings! " +StartDate);
return;
}
var booking = response.Bookings.SingleOrDefault( b => b.BookingId == bookingCode);
if (booking == null)
{
this.WriteToFile("Sorry could not find your source of booking");
return;
}
var bookingSource = booking.BookingSource;
this.WriteToFile("Booking Source =" + bookingSource + "");
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 2 at 22:30









John WuJohn Wu

31.3k42753




31.3k42753













  • thanks this code works fine

    – Luke Luvevou
    Jan 2 at 23:25











  • but it seems that it keeps on returning null with the message "Sorry could not find your source of booking" how do i ensure that it returns something :

    – Luke Luvevou
    Jan 3 at 1:50













  • Got me. Could be a bug in the service, or maybe you have the wrong booking number.

    – John Wu
    Jan 3 at 2:48











  • i have even added an existing booking number and still it gives the "Sorry could not find your source of booking"

    – Luke Luvevou
    Jan 3 at 3:21











  • i have updated you code and it works i also updated the service reference as well..on visual studio.. and i able to pull bookings/data

    – Luke Luvevou
    Jan 9 at 23:50



















  • thanks this code works fine

    – Luke Luvevou
    Jan 2 at 23:25











  • but it seems that it keeps on returning null with the message "Sorry could not find your source of booking" how do i ensure that it returns something :

    – Luke Luvevou
    Jan 3 at 1:50













  • Got me. Could be a bug in the service, or maybe you have the wrong booking number.

    – John Wu
    Jan 3 at 2:48











  • i have even added an existing booking number and still it gives the "Sorry could not find your source of booking"

    – Luke Luvevou
    Jan 3 at 3:21











  • i have updated you code and it works i also updated the service reference as well..on visual studio.. and i able to pull bookings/data

    – Luke Luvevou
    Jan 9 at 23:50

















thanks this code works fine

– Luke Luvevou
Jan 2 at 23:25





thanks this code works fine

– Luke Luvevou
Jan 2 at 23:25













but it seems that it keeps on returning null with the message "Sorry could not find your source of booking" how do i ensure that it returns something :

– Luke Luvevou
Jan 3 at 1:50







but it seems that it keeps on returning null with the message "Sorry could not find your source of booking" how do i ensure that it returns something :

– Luke Luvevou
Jan 3 at 1:50















Got me. Could be a bug in the service, or maybe you have the wrong booking number.

– John Wu
Jan 3 at 2:48





Got me. Could be a bug in the service, or maybe you have the wrong booking number.

– John Wu
Jan 3 at 2:48













i have even added an existing booking number and still it gives the "Sorry could not find your source of booking"

– Luke Luvevou
Jan 3 at 3:21





i have even added an existing booking number and still it gives the "Sorry could not find your source of booking"

– Luke Luvevou
Jan 3 at 3:21













i have updated you code and it works i also updated the service reference as well..on visual studio.. and i able to pull bookings/data

– Luke Luvevou
Jan 9 at 23:50





i have updated you code and it works i also updated the service reference as well..on visual studio.. and i able to pull bookings/data

– Luke Luvevou
Jan 9 at 23:50




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54013663%2ftrying-to-get-data-from-wsdl-using-c-sharp%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement

'app-layout' is not a known element: how to share Component with different Modules