|
A work, I have just been assigned to consume a web service using C# 2010. The web service is suppose to give me a list of customer ids. I need to obtain the list of customer ids by working with an .xsd file. (By look at the documentation for the xsd file, it looks like xml to me.) In addition from this web service, I obtain suppose to obtain files that I can download that are in word, pds, and tiff formats.
By the way, I know that I can connect to the web service since I have a command script, that can connect to ther web service. (The command script was written by the company that wrote the web service.)
Due to the requirements listed above, I am wondering if you can tell me the following:
1. How to connect a C# console, desktop, and/or web app to the web service?
2. How can I obtain the xsd file from the web service and transverse the xsd file to obtain the data I am looking for?
3. How can I download the word document, pdf, and/or tiff file from the web service?
|
|
|
|
|
classy_dog wrote: How to connect a C# console, desktop, and/or web app to the web service?
It depends on the type of web service, but if it's a Microsoft SOAP web service, you should be able to get info about it by visiting the WSDL page for it. So, if the web service is:
site.com/SomeService.asmx
You can view the WSDL at:
site.com/SomeService.asmx?wsdl
Also, it mostly doesn't matter what type of app you are making... they all connect to web services the same way. However, if you are connecting via JavaScript, that is different and introduces some security considerations.
In general, you connect to a web service using a proxy class. There are a couple ways to generate one. For one, you can "add a service reference" in Visual Studio, and that will create the proxy class for you. I prefer to use a the WSDL.exe command line tool. To use it, you must first open the Visual Studio command prompt:
Start... All Programs... Microsoft Visual Studio 2010... Visual Studio Tools... Visual Studio Command Prompt (2010)
You then type "wsdl.exe /?" to see how to use it. However, taking our example, you could type this:
wsdl.exe /langauge:cs /namespace:Whatevs /out:C:\SomeServiceProxy.cs http://www.site.com/SomeService.asmx?wsdl
I forget if you actually need to type in the "?wsdl" or not. If it works, you should see a file on your C: drive called SomeServiceProxy.cs. It should be a C# class in the "Whatevs" namespace. Bring this file into your Visual Studio project, create an instance of the class, and you should be able to call methods on it just like any normal method (e.g., SomeServiceProxy.GetCustomerIDs() ). The proxy class hides the web service details... instances of classes are returned, so you never need to mess with the icky details like serialization and deserialization. .Net web service proxy classes handle this for you.
classy_dog wrote: How can I obtain the xsd file from the web service and transverse the xsd file to obtain the data I am looking for?
I forget what the difference is between XSD and WSDL, but I think XSD is the old version or something like that (or maybe an alternative format). If you create a proxy class, however, you shouldn't have to worry about XSDs and WSDLs.
classy_dog wrote: How can I download the word document, pdf, and/or tiff file from the web service?
Files will probably be returned from a web service as a byte array. Other info, like the filename, may also be returned (in the case of a filename, it would be returned as a string). Save the byte array to a file and you are good to go. If you are returning the file from a webpage, that's a little different, but not much (e.g., you'll have to add some HTTP headers and such).
By the way, if this is all overwhelming, I recommend buying a book that describes how to use web services. I read one that was called something like "SOA in .Net" (SOA meaning Service Oriented Architecture). If you consider things like security and alternative architectures (e.g., REST), it can get complicated.
|
|
|
|
|
I have the additional comments/questions to ask:
1 When I call the web service and ask for a document, the web service places the document in a directory path that I specify in an app.config file for the console application I just started to write. I always receive the file in a PDF format and not in a word document format. Thus if I want to convert the PDF file to a word document, I probably need to do the conversation after I rewceive the file, correct? If I am wrong, how would I accomplish this goal?
2. when I call the web service and from a command dos prompt, I have been directing the output to a text file for now. However the output I receive is the command I wrote plus the xsd file response. I know that I will need obtain the response in another way besides redirecting the output to a text file. Thus can you tell me how I can save the xsd file format reponse? In addition, can you tell me how I can determine how to parse the xsd results so I can obtain the data I am looking for?
|
|
|
|
|
1) I don't know what the web service is capable of, so I suppose if you want the PDF as a word doc, then you'll have to convert it.
2) I'm not sure what you're doing, but it doesn't sound like you're calling the service via a proxy class. If you're doing something custom, I can't help you. Though, I am pretty sure an XSD isn't supposed to contain actual data... just shows the format of what data can be returned.
|
|
|
|
|
If you have the data contract (the xsd file), you can generate the code that you need for the data types using this[^] product. However, from the xsd, you don't get the operations that can be performed, you merely get the data structures. You are going to need to write the code to interact with the operations yourself.
classy_dog wrote: 1. How to connect a C# console, desktop, and/or web app to the web service?
WSCF.blue will give you the ability to generate the service reference code.
classy_dog wrote: 2. How can I obtain the xsd file from the web service and transverse the xsd
file to obtain the data I am looking for?
You already have the xsd file. You just said so.
classy_dog wrote: 3. How can I download the word document, pdf, and/or tiff file from the web
service?
You don't. You get whatever representation of these that the service returns (possibly a base 64 encoded string) and convert that at your end and save to disk.
|
|
|
|
|
classy_dog wrote: need to obtain the list of customer ids by working with an .xsd file
The xsd is a definition of what the xml will look like. Thus you don't get the ids from an xsd source.
|
|
|
|
|
Hi
Has anyone tried to access Comupter Associates ( CA) TOP-SECRET thru LDAP in C# code. If yes please respond as I would like to get some specific info to do the resource permissions checks.
Thanks, Ravi
|
|
|
|
|
Considering the verticle nature of your request, more than likely not.
The best place to ask about using a particular library or product is the manufacturer of the library or product.
|
|
|
|
|
I'm having a tough time converting month, day, and year into hex then byte[]. I did an internet search and I'm not finding anything that is similar enough to provide the link to. This is what I have so far from before I realized I needed the hex, but I do need the 2-digit mo/day/yr before it's hex. I'm a little confused about converting to hex since I would normally take the number and use ToString("X"), but it doesn't seem to apply here since I'm applying the formatting to get it to the 2-digit month, for example.
DateTime mfg = DateTime.Now;
mfgDate_mo = new byte[mfg.ToString("MM").Length * sizeof(char)];
convertStringToByteArr(mfg.ToString("MM"), ref mfgDate_mo);
mfgDate_dy = new byte[mfg.ToString("dd").Length * sizeof(char)];
convertStringToByteArr(mfg.ToString("dd"), ref mfgDate_dy);
mfgDate_yr = new byte[mfg.ToString("yy").Length * sizeof(char)];
convertStringToByteArr(mfg.ToString("yy"), ref mfgDate_yr);
private void convertStringToByteArr(String theString, ref byte[] theByteArr)
{
System.Buffer.BlockCopy(theString.ToCharArray(), 0, theByteArr, 0, theByteArr.Length);
}
|
|
|
|
|
I'm sorry, but your description doesn't make much sense to me. I've read it a couple of times and I can't visualise what you are trying to do. Given an input of todays date, what are you expecting to see in the byte array? If you could illustrate this, then perhaps I can help.
|
|
|
|
|
For example, today's date is 8/20/2012. I need to take the 8, represent it as 08, convert it to Hex which is still 08 for that one, then put it in a byte array. For the year, I need to take the 12, which is already 2 digits, then convert to hex, which is 0C, then put it in byte array.
|
|
|
|
|
So just use the following to convert:
private byte[] Convert(int datePart)
{
string convertedPart = datePart.ToString("X2");
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
return enc.GetBytes(convertedPart);
}
|
|
|
|
|
Thanks! I'll give it a try. It seems like it will work with adding a conversion from DateTime to integer.
int mfgDate_mo_int = mfg.Month;
|
|
|
|
|
Why don't you just do binary serialization to a byte array? It'll be a little bigger then what you are doing because of the meta data, but if you want it really light weight, I don't really get the hex step. Just store the month, day and year?? Also, don't store just the 2 digit yr or you'll have Y2K issues.
|
|
|
|
|
I have to convert to hex and do 2-digits because of system requirements.
|
|
|
|
|
Are the requirements fixed? A DateTime is really a long internally (Ticks), which of course can be stored in/retrieved from 8 bytes very easily.
|
|
|
|
|
Yes, the requirements are fixed. This is related to a chip layout that a contractor designed years ago. Thanks for the suggestions, though!
|
|
|
|
|
No problem. Did you get it working?
|
|
|
|
|
Yes. I still have to try writing the data to the chip to test it, but hopefully all is good (encoding) when I do.
|
|
|
|
|
Hello,
I wanted to use a (flag) enum as index to access the single flag values.
Instead of
<CheckBox IsChecked="{Binding Obj[1]}" ...
I hoped that I could use something like
<CheckBox IsChecked="{Binding Obj[TestEnum.Enum1]}" ...
with some helper object providing an index operator. The first works, the second does not...
Additionally: Can I use an expression (for example an extension method
TestEnum.Enum1.DoSomething()
(which returns a different enum item of the same type) instead of the enum item name for the Binding?
Alex
|
|
|
|
|
Alex, in order to use an enum, you actually need to provide some instance information to WPF for it to be able to "understand" it. To do that, you need to set up an ObjectDataSource that binds in the enum. There's an example here[^] that shows how to do this.
You might also want to look at this[^] handy article.
BTW - you really should have asked this in the WPF forum. This has nothing to do with C#.
|
|
|
|
|
Sorry, I missed that there is an WPF forum (hidden behind Silverlight...).
Indeed, the samples shown in your links do it the other way round - get the string from the enum value. I needed the value from the string.
My error was simply to use the full name
"{Binding Obj[TestEnum.Enum1]}"
instead of simply
"{Binding Obj[Enum1]}"
The latter works now.
Alex
|
|
|
|
|
I'm glad you've got it working.
|
|
|
|
|
And for the expression
{Binding Obj[Enum1.DoSomething()]}
I found a simple workaround for my case.
I simply use multiple properties:
{Binding ObjDoSomething[Enum1]}
{Binding ObjDoSomethingElse[Enum1]}
which internally call the extension method.
Alex
|
|
|
|
|
I dunno anything about WPF, but to answer the question; yes to all. To answer the questions in reverse order;
LionAM wrote:
Additionally: Can I use an expression (for example an extension method
TestEnum.Enum1.DoSomething()
Yes, see example-code below (tested under Mono);
public enum TestEnum: int
{
Enum1 = 3,
EnumZwei = 9
}
public static class MyExt
{
public static TestEnum DoSomething(this TestEnum e)
{
return TestEnum.EnumZwei;
}
}
class Program
{
public static void Main (string[] args)
{
Console.WriteLine(TestEnum.Enum1.DoSomething());
}
}
LionAM wrote: I hoped that I could use something like
<CheckBox IsChecked="{Binding Obj[TestEnum.Enum1]}" ...
with some helper object providing an index operator. The first works, the second does not...
With a little helper you can. Add the method below;
public static class MyExt
{
public static string Parse(this string SomeString)
{
foreach (var enumVal in Enum.GetValues(typeof(TestEnum)))
{
string enumValAsString = String.Format("{0}.{1}",
enumVal.GetType().Name, enumVal);
int enumValAsInt = (int)enumVal;
if (SomeString.Contains(enumValAsString))
{
SomeString = SomeString.Replace(enumValAsString, enumValAsInt.ToString());
}
}
return SomeString;
}
}
class Program
{
public static void Main (string[] args)
{
string s = "{Binding Obj[TestEnum.Enum1]}";
Console.WriteLine(s);
Console.WriteLine(s.Parse());
}
}
Enjoy
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|