consume java web service from C#
-
Wednesday, November 24, 2010 1:55 AM
I'm new to consuming a non .NET web service from .NET. Here is my dilemma, I have a java web service that is using SOAP, I have a web page that I need to consume the Java web service via SOAP, can anyone point me in the right direction to get started?
1. is there a different way to consume the java web service other then [add web reference] and then point to the WSDL location?
2. what do i need to pass SOAP envelopes to the web service?
any help is greatly appreciated.
- Moved by John SaundersMVP, Moderator Wednesday, November 24, 2010 5:53 PM wcf q (From:ASMX Web Services and XML Serialization)
All Replies
-
Wednesday, November 24, 2010 7:59 AM
Hi,
If you know the WSDL URL then better way to consume is "Add Service Reference"
Thanks,
Prabhas
Please mark posts as answers/helpful if it answers your question -
Wednesday, November 24, 2010 12:06 PMI did that but since the wsdl is throwing back errors, I need to grab the SOAP messages that are being passed to the web service
-
Wednesday, November 24, 2010 5:20 PMModerator
No, actually, you need to determine what errors the WSDL is "throwing", and resolve them.
When you have issues with consuming a WSDL, I recommend using the command-line SVCUTIL.EXE program. It does the same thing as "Add Service Reference", but errors will be easier to see.
Also, since you are (fortunately) able to use "Add Service Reference", this is a WCF question, and I'll move it to the WCF forum.
John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects -
Thursday, November 25, 2010 8:18 AMModerator
Just to add some more informations:
There are several means you can consider when you try to consume a XML webservice(no matter what platform it is built upon) from .NET client:
1. If a well-defined WSDL metadata document is provided, it is recommeded that you use "Add WebReference"(for traditional ASMX webservice client) or "Add serviceReference"(for the WCF based client proxy) to generate proxy class and use proxy class to consume the service.
2. If the service or the request/response message of the service operations are not very complicated and won't involve complicated WS-* protcocols(such as ws-security). Then you can ask for a sample SOAP request/response message from the service provider. After that you can directly use HttpWebRequest component to call the service and maually generate request message via XML document classes and also receive the response as raw XML document and parse it.
#Accessing Webservice by using Sys.Net.WebRequest
http://www.dotnetfunda.com/articles/article480-accessing-webservice-by-using-sysnetwebrequest-.aspx#Invoking Web Service dynamically using HttpWebRequest
http://geekswithblogs.net/marcel/archive/2007/03/26/109886.aspx
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Proposed As Answer by Leonid GanelineMVP, Moderator Wednesday, December 01, 2010 2:13 AM
- Marked As Answer by Mog LiangModerator Wednesday, December 01, 2010 7:17 AM
- Unmarked As Answer by Mog LiangModerator Wednesday, December 01, 2010 7:18 AM
-
Tuesday, November 30, 2010 12:28 PM@Steven, after talking to the vendor more about this web service they provided, its a SOAP API that is requiring SOAP messages to be sent for authentication. Is there a way to dump the XML being passed to the WSDL so we can look at that as well to see what format it's in? I found out that the auth information needs to be a single byte and not a multibyte and the bytes are converted to a hexString and not base64
-
Tuesday, November 30, 2010 12:30 PM@John, Its not a WCF service its a regulare XML Based SOAP APi WSDL that was created in Java, and I have to consume it from .NET using SOAP calls to it for authentitcation so I can use the methods within the service
-
Tuesday, November 30, 2010 5:07 PMModerator
WCF is the correct way to do this in .NET. Simply use "Add Service Reference", then consume the classes that generates. See How to Consume a Web Service. Even though the example service is written in WCF, the exact same method should work with any SOAP web service, even one written in Java.
John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects- Proposed As Answer by Leonid GanelineMVP, Moderator Wednesday, December 01, 2010 2:14 AM
-
Tuesday, November 30, 2010 6:41 PM@John, I haven't used a WCF service yet, so for this to work, do I have to create a WCF service first, or just add my WSDL reference to my existing web app as a [Add Service Reference]?
-
Tuesday, November 30, 2010 7:25 PMModeratorNo. You do not need a WCF service. Just use "Add Service Reference" and give the URL of the WSDL of the Java web service.
John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects -
Tuesday, November 30, 2010 9:48 PM
We just receintly published a whitepaper that talks about interoperability between Java and .NET you can find it here: http://msdn.microsoft.com/en-us/library/ff842400.aspx
Thanks,
Michael Green
WCF Documentation Team- Proposed As Answer by Steven Cheng - MSFTMicrosoft Employee, Moderator Wednesday, December 01, 2010 3:16 AM
- Marked As Answer by Mog LiangModerator Wednesday, December 01, 2010 7:17 AM
-
Wednesday, December 01, 2010 3:19 AMModeratorHi,
So do you currently have or managed to get a working client (java based) that can correctly consume the java service? If so, you can use it to consume the service and use some network tracing tools such as TcpMon to capture the underlying HTTP request/response message. Thus, you can inspect the messages and learn the detailed XML format the service will expect and return to client. If you later want to build a .NET based service client via simple WebRequest classes, you need to manually build the service request message based on the format.
Or if the servcie has a well-defined WSDL document(metadata), as other member mentioned, you should use "Add ServiceReference" to generate a WCF/.NET based service proxy class to consume the service.
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
Wednesday, December 01, 2010 12:51 PM
@Steve: I can connect to it and call methods in the API from a PHP page, however, I cannot connect to it from .NET.
I would I manually build the service request? This is my first Java web service I encountered with these issues when calling from .NET, I usually 'add a web reference' to the WSDL file and I'm off and running, but this one isn't working as such.
-
Wednesday, December 01, 2010 5:34 PMModerator
You know, you still haven't told us what errors the WSDL is "throwing". "Add Service Reference" is the correct way to do this, assuming the WSDL is valid. Let's find out what problem .NET is having with the WSDL and get you moving.
John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects -
Thursday, December 02, 2010 12:09 AM
I just keep gettting 'authentication failed'
I have to pass a datetime and the id encyrpted via SHA1 encryption. The WSDL works from a PHP file just fine and I need to convert this line of PHP code to .NET
$signature = hash_hmac('sha1', $string, $this->Key);
if you know a way to this kind of encyryption in C#, please advise. the sting i need to encrypt looks like this:
2010-12-02T00:09:28server_123459089898
-
Thursday, December 02, 2010 12:15 AMModerator
Note that this is not an error with the WSDL. You simply have to implement in C# the code that is already implemented in PHP.
I recommend you look up the PHP documentation on this function, then ask how to implement it in .NET on the Common Language Runtime forum.
John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects -
Thursday, December 02, 2010 12:31 AMThe PHP code hash_hmac, translate to HMACSHA1 in .NET, i just need to figure out how to convert that entire line to C# so I can get it working
-
Thursday, December 02, 2010 3:41 AMModeratorHi,
So based on your further description, the "authentication fail" error occurs when you try "add webreference" against the service. If so, it is likely the WSDl document of the service hasn't been correctly obtained (when adding webReference), you can use fiddler to watch the http traffic to confirm this.
Since you can get it work with PHP code, I think you can consider the following workaround:
* you can first use PHP code or related class to access the webservice's WSDL document and download it (save to a local folder).
* use Visual Studio Add ServcieReference(or WebReference) against the local saved wsdl file and generate proxy class based on it.
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
Thursday, December 02, 2010 12:14 PM
@Steve, we did all everything you mentioned. The 'auth fails' when we try to call a method within the service, we can add the service just fine within VS, we create the object to the service, its when we try to call a method is when we get 'auth failed'.
however, when we call that same method in the same WSDL from the PHP file it works. Though we did notice that the PHP and the .NET page are HASHing the same date differently, meaning if we have this string 2010-12-02T12:13:22Server_1234567, and run it through the PHP file and the .NET page, the HASH from both don't match, and there is were we think the problem is laying now due to we need that string HASHED so it can be passed in the Auth Header to the WSDL.
-
Thursday, December 02, 2010 8:48 PM
I got it working, when I started doing a string by string comparision with the HASH between the php and the .NET, it came down to I had to hash the .NET hash, then modify the timestamp to remove the milliseconds and it worked.
- Marked As Answer by CSharpCoder1 Thursday, December 02, 2010 8:48 PM
-
Thursday, May 03, 2012 11:41 PM
I am getting the same error when consuming java web service. Can you little bit explain more how you manage to resolve this error. If possible just guide me with sample code.Really appreciate your help
Thank You.
-
Monday, May 28, 2012 12:32 AM
I manage to solve this issue . just refer my blog.
http://maheshde.blogspot.com.au/#!/2012/05/develop-web-client-to-consume-https.html

