Trying to get data from wsdl using c#
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
add a comment |
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
Have you tried setting a breakpoint and stepping through the code? Do you think it could be important to show the definition ofWriteToFile
? 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 callingGetModifiedBookings
but then overwriting the response'sBookings
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 thatbookings.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
add a comment |
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
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
c# asp.net web-services wsdl
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 ofWriteToFile
? 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 callingGetModifiedBookings
but then overwriting the response'sBookings
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 thatbookings.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
add a comment |
Have you tried setting a breakpoint and stepping through the code? Do you think it could be important to show the definition ofWriteToFile
? 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 callingGetModifiedBookings
but then overwriting the response'sBookings
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 thatbookings.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
add a comment |
1 Answer
1
active
oldest
votes
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 + "");
}
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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 + "");
}
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
add a comment |
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 + "");
}
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
add a comment |
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 + "");
}
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 + "");
}
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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'sBookings
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