• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2096
  • Last Modified:

I need help with SOAP client

Ok, so I want to tap into a web service...I have the WSDL, and know the format my XML needs to be in. I just can't figure out the client portion in vb.net!! If someone could provide me with a really simple client to send the XML via SOAP and accept the return XML, that would be great! Not sure if it matters, but I am sending the request over a SSL connection.

One thing I forgot to mention.....when I go to view the WSDL I have to enter a user/pass, does that mean that somewhere in the SOAP request I need to include my username and password?

Thanks in advance
0
FirePits
Asked:
FirePits
  • 3
  • 2
1 Solution
 
Geert BormansCommented:
Hi FirePits,

One thing you can do is download Altova XMLSpy enterprise (www.altova.com)
that is a good tool to explore how the soap envelopes are created

- start XMLSpy
    + in the SOAP menu pick "Create new soap request"
    + in "enter the WSDL..." put the wsdl address: "http://www...."
    + press OK
    + you will get your operations listed
    + double click on the operation you want to use
    + you will now see a soap XML file... that is the mock-up of what you have to send to the service
    + edit the XML, and fill in the parameters
    + in the SOAP menu "send request to server"
    + you see a soap return message
    + you just did your first soap test
    + for doing this in JavaScript, you need to know the soap message you sent and the return message (to get the info from)
       you also need the "action"
    + in the SOAP menu: "change request parameters"
    + copy what is under soapaction in the http soapaction header when required (in your javascript later)

in this story, replace JavaScript with your language of choice

please note that vb.net likely has some controls to make this easier

the password/username are likely in the header of your soap request... XML Spy will show you where to add them

Cheers!
0
 
FirePitsAuthor Commented:
Thank you Gertone, this helped tremendously!
0
 
rdcproCommented:
In VB.NET (or any other .NET language, for that matter) it's very easy to connect to a web service.  You don't have to worry about SOAP or any of that.  There are at least two ways to do this.  

Method 1

There is a utility in the .NET SDK that you can download from Microsoft that will generate the proxy code you'll need to interact with the web service.  It's called WebServiceUtil.exe.  Among other things, it can generate the proxy code, using a command line like:

WebServiceUtil /c:proxy /pa:http://yourDomain/someFolder/yourWebService.asmx?wsdl /l:visualbasic /n:Namespace

This will create a compilable file, like MyWebService.vb

You compile this, and then add the DLL as a reference to your VB project.  Treat it like any other object--you simply call it's methods to invoke the web service.

Method 2
In your project, add a Web Reference.  This generates the proxy code right in your project.  For example, in a recent MS Content Management Server (MCMS) site that I build, I used SharePoint to provide search services.  I make a web service call to the SharePoint search service at http://ServerName/_vti_bin/search.asmx

When I add the web reference, I get a bunch of proxy code in a file called Reference.cs.  In that file there is this string method:

        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("urn:Microsoft.Search/Query",  
                RequestNamespace="urn:Microsoft.Search", ResponseNamespace="urn:Microsoft.Search",
                Use=System.Web.Services.Description.SoapBindingUse.Literal,
                ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
        public string Query(string queryXml) {
            object[] results = this.Invoke("Query", new object[] {
                        queryXml});
            return ((string)(results[0]));
        }

The proxy stub handles all the conversions to SOAP and all that, so I call the web service simply by

results = myQuery.Query(strQuery);

Ok, its a bit more complicated, but not by much.  You set things like credentials and timeouts and such like this:

// Create the secondary web service query proxy
QueryService querySecondary = new QueryService();
querySecondary.Url = sUrl;
querySecondary.Timeout = statusTimeout;
NetworkCredential myCredentialsSecondary = new NetworkCredential("","","");
myCredentialsSecondary.Domain = sDomain;
myCredentialsSecondary.UserName = sUser;
myCredentialsSecondary.Password = sPass;
querySecondary.Credentials = myCredentialsSecondary;
try
{
      spsSecStatus = querySecondary.Status();
}
catch (Exception SpsSecEx)
{
      bSearchError = true;
      sbResults.Append("Secondary SPS Server Status: " + spsSecStatus + "<br>");
      Common.LogError(SpsSecEx,EventLogEntryType.Error,5000);
}


Really, in .NET, it's a piece of cake.  There are a number of examples of this in the various SDKs and articles in MSDN.

Regards,
Mike Sharp
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
FirePitsAuthor Commented:
Thanks Mike,
So, I added the web reference in my project. However, it didn't produce a class as expected. Once I added the web reference, the only files created were a .disco, .discomap and wsdl file. Am I doing something wrong??

Thanks again for your help
0
 
rdcproCommented:
It's a bit hidden.  Expand the map, and you should see it there.  In my project, adding a web reference adds:

Reference.map
Search.disco
Search.wsdl

The code is buried under Reference.map.
Reference.map
    Reference.cs
Search.disco
Search.wsdl

Which version of Visual Studio are you using?

Regards,
Mike Sharp
0
 
FirePitsAuthor Commented:
Related to my question, can anyone help with this problem?

I have created a proxy class using the wsdl.exe tool. There are certain functions in the proxy class that have a return value, and I have successfully output those return values. However, there is one particular function that I will need to access 90% of the time that does not have a return value. What I am trying to figure out is how to access the response xml from that function request, or access the object that I'm assuming the proxy class creates with the response.

I have been using a program called XMLSpy to test my requests, in pure xml not using a proxy class, and I select the same function that I am using with my proxy class, but XMLSpy shows me the response xml from my request. I am not sure how XMLSpy is accessing the response xml, but at least I know it's receiving it.

I searched the proxy class for a Deserialize() method, but wasn't able to find one?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now