Link to home
Start Free TrialLog in
Avatar of lapucca
lapucca

asked on

Problem adding Java SOAP web services to an asp.net/C#.net project RSS

Hi, I'm using vs2013 , asp.net and C#
Do I need to add the Java SOAP web services differently than when simply adding a ASP.net web api?

The API requires credential so I enter the service account credential then it just repeatedly popping up the Web Discovery Service dialog as attached file, and asked is I want to continue.  I clicked yes, enter the credential again and it just goes right back to the same dialog.  What's going on here?  It doesn't complaint that it's credential, instead is just goes in a loop of keep asking me to enter credential.

Okay, I finally see the Error detail in the Add Service Ref dialog.  It says the following.  Does this mean the credential I entered is invalid?  

"Metadata contains a reference that cannot be resolved: 'https://xxxxx.xxx.xxx.xxx/yyyy'.
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Basic realm="XXXXXX API"'.
The remote server returned an error: (401) Unauthorized.
If the service is defined in the current solution, try building the solution and adding the service reference again."

This is what the 3rd party vendor says about their APIs, below. Do I have to do anything in the web.config file to be able to add these references? Like discussed here, http://stackoverflow.com/questions/1365163/can-not-call-web-service-with-basic-authentication-using-wcf


The API service endpoint employs the use of Simple Object Access Protocol (SOAP, version 1.1) as the transport specification and Hypertext Transfer Protocol Secure (HTTPS) as the transport protocol. XML is used as the data exchange format to ensure the validation of structured message data conforms to the specification of the API. The API also employs the use of Message Transmission Optimization Mechanism (MTOM), a method for efficiently sending/receiving binary data, utilized when exchanging documents.

The XXXXX API makes available a Web Service Description Language (WSDL), published through its service endpoint, which describes the manner in which the service may be called, details the available service operations, and specifies the message structures.
A client application must be built in congruence with the service specification as provided by the WSDL. Any number of technologies may be used to build the client.



Thank you.
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

There are two different ways to add a service reference in Visual Studio 2013--Service Reference and classic Web Reference

Steps to Add Web Reference dialog:

1) Select Add Service Reference from right-clicking on project Reference node in Solution Explorer

2) Click on the Advanced button

3) Click the Add Web Reference button at the bottom of the dialog

Another way, if the service supports cookies, would be to access the service in browser, and log in with the proper credentials.

Also, is there a URL for the WSDL?  You could add from the WSDL URL, and then override the GetWebRequest to add the basic authentication headers:

protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
    var req = base.GetWebRequest(uri);
    req.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes("username:password")));
    return req;
}

Open in new window

Avatar of lapucca
lapucca

ASKER

Hi, thank you for the reply.
I tried using the Add Service and got the error message as stated in my question post. I then tried adding the web service yesterday as well ,the dialog said it generate code based on .net framework 2.0, does it matter that I'm in VS2013?

All below occurred in the dialog of "Add a Web Reference".
I clicked to "Add a Web Referemce" and I got the same 404 error, "The requested resource (/yyy) is not available.", or not found, after I repeated enter my credential and eventually had to click on the Cancel button otherwise it keeps asks for credential.  Why is that so?

I then use the wsdl url, 'https://xxxxx.xxx.xxx.xxx/yyyy/api?wsdl '.  It asked me to enter credential a couple of times while keep dispalying the Security warning dialog, attached, several times.  After all that, it then does display all the methods of the web service.  However, can you take a look at the warning message on top of the screen about security.  When I clicked on that warning, I have option to "allow blocked content" or "Open desktop".  If I select the "allow blocked content" option then the list of methods turns into XML format.  Does it matter or not if I allow the content?

The web service, with the name I gave it, is now listed under a Web Reference folder.  I tried adding the "using" statement at top of my cs code and it can't find it.  However, inside of my Page_Load event, I can reference the Web Reference Name that I gave it.  But, in the code the intellisense only shows Delegates and Classes, no methods that I can call.  Those methods I saw when adding this web reference does not show up at all!  So frustrating!

Also, what's the proper way to add references?  What's the difference when I add using the url without the /api?wsdl, which I think is the wsdl file.

Thank you.
Secruity-Warning.jpg
add-wsdl.jpg
Without specifics about the web service, it is more difficult to suggest a course of action.

1) The security warning means that the WSDL has URLs that are not HTTPS:

2) The "To help protect your security...active content" warning suggests that there is script in the WSDL.  I haven't worked with web services that had "active content" before.  I believe that Visual Studio uses Internet Explorer, which has a setting to allow active content.  I am not sure that allowing active content will help you.

3) What version and service pack release level are you using with Visual Studio 2013?
Avatar of lapucca

ASKER

My VS 2013 info
Microsoft Visual Studio Ultimate 2013
Version 12.0.31101.00 Update 4
Microsoft .NET Framework
Version 4.6.00057

Installed Version: Ultimate

I followed from steps 2 of Add Web Services, http://www.codeproject.com/Articles/32313/How-to-invoke-Java-web-service-in-ASP-net-using-C 
But I can't reference the web service with using or in my code to access the methods.  Maybe I need to use an older version of VS?
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lapucca

ASKER

I had to instantiate a proxy class and then the intelligent would expose all methods and parameters...   Right, the vendor wasn't nice enough to share which class I need to instantiate but I found it/guessed it.  Thank you for all your help.

The server is refusing the request/connection.  I need to open another question about passing credential here.  Thank you.
If the web service is using Basic Authentication, you need to pass them in, and I showed you that code earlier:

protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
    var req = base.GetWebRequest(uri);
    req.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes("username:password")));
    return req;
}

Open in new window