Solved

Call webservice from vb.net

Posted on 2010-09-22
20
1,694 Views
Last Modified: 2012-05-10
I have a wsdl file that I added a reference to in my project how do I actually call the service through a forms application?
0
Comment
Question by:cobolinx1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 5
  • 3
  • +2
20 Comments
 
LVL 7

Assisted Solution

by:illusio
illusio earned 300 total points
ID: 33734713
If you did "Add service reference" and you browsed to your WSDL file and it then added a service reference, then you use the selected namespace to search for the class ending on "client".
you do:

Using client as blablablaClient = new blablablaClient() ' or new blablablaClient(someweirdUrl)
       client.AVeryCoolMethod(SomeReallyUseFullArguments)
End Using

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 33734719
Right-click your project in Solution Explorer and then select Add Service Reference. In the address field, enter the path to your WSDL file and then click Go. In a few seconds, you should see your service listed under Services. Select it, change the Namespace if you like, then click OK.

Alternatively, I believe you can add the WSDL to your project as a New Item, then perform the above. Instead of entering the path to the file, you would click Discover, and then Services in Solution. The remaining steps are the same.
0
 
LVL 5

Expert Comment

by:roxviper
ID: 33734740
0
2017 Webroot Threat Report

MSPs: Get the facts you need to protect your clients.
The 2017 Webroot Threat Report provides a uniquely insightful global view into the analysis and discoveries made by the Webroot® Threat Intelligence Platform to provide insights on key trends and risks as seen by our users.

 

Author Comment

by:cobolinx1
ID: 33734797
This appears to be calling it:

Using client as blablablaClient = new blablablaClient() ' or new blablablaClient(someweirdUrl)
       client.AVeryCoolMethod(SomeReallyUseFullArguments)
End Using


But I get the following error message:
No Security header in message but required by policy.

0
 

Author Comment

by:cobolinx1
ID: 33734801
I have a username and password if it needs it but how would I add it?
0
 

Author Comment

by:cobolinx1
ID: 33734994
I added a username and password but still get the No Security header in message but required by policy error message.
client.ClientCredentials.UserName.UserName = "myid"
 client.ClientCredentials.UserName.Password = "mypwd"
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 33735059
Does your web service require certificate authentication?
0
 

Author Comment

by:cobolinx1
ID: 33735146
It looks like its just looking for the security token username and password... isn't that the same as the client credentials?
0
 

Author Comment

by:cobolinx1
ID: 33735411
No I confirmed it doesn't require certificate authentication.
0
 
LVL 7

Expert Comment

by:illusio
ID: 33735475

Try using the wsHttpBinding binding with message security on.
Or post your WSDL is that doesn't do the trick. In the WSDL the required tokens can be read - very obscure  things, created to make you feel miserable.
0
 

Author Comment

by:cobolinx1
ID: 33736215
I don't know what you mean


Using client as blablablaClient = new blablablaClient() ' or new blablablaClient(someweirdUrl)
       client.AVeryCoolMethod(SomeReallyUseFullArguments)
client.ClientCredentials.UserName.UserName = "myid"
 client.ClientCredentials.UserName.Password = "mypwd"
End Using
0
 

Author Comment

by:cobolinx1
ID: 33736241
Sorry I don't know what you mean how would implement that??


Here is the part in the wsdl that I think the username and password are passed to

<wsp:Policy s0:Id="Auth.xml">
<wssp:Identity xmlns:wssp="http://www.bea.com/wls90/security/policy">
<wssp:SupportedTokens>
<wssp:SecurityToken TokenType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken">
  <wssp:UsePassword Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText" />
  </wssp:SecurityToken>
  </wssp:SupportedTokens>
  </wssp:Identity>
  </wsp:Policy>

Using client as blablablaClient = new blablablaClient() 
client.ClientCredentials.UserName.UserName = "myid"
 client.ClientCredentials.UserName.Password = "mypwd"
       client.AVeryCoolMethod(SomeReallyUseFullArguments)
End Using

Open in new window

0
 
LVL 3

Expert Comment

by:Deepu Sreedhar
ID: 33743409
You should use WSE tool (which can be downloaded from Microsoft) to configure your .config file to insert a policy file that uses Username & Password Credentials.
0
 
LVL 3

Accepted Solution

by:
Deepu Sreedhar earned 200 total points
ID: 33743437
See the picture attached. and let me know if you need more help on this.
WSE.JPG
0
 
LVL 7

Assisted Solution

by:illusio
illusio earned 300 total points
ID: 33743529
Creating a service reference normally adds some text to the app.config (or web.config) file. In there you find the ABC (Address, Binding, Contract). You see what type of binding that is being used. Put it on wsHttpBinding. To make things less complicated you can use the WCF Configuration Editor (it's under Tools in the visual studio), then open your config file and you'll have a nice gui to change your config. In that gui change the BasicHttpBinding to WsHttpBinding and try again.
From what I see, username and password is all it asks. So on that part you are on the right track.

0
 

Author Comment

by:cobolinx1
ID: 33744084
I tried switching to wshttpbinding and got the error below. I switched it back to custom and I get the No Security header in message but required by policy.

Downloaded the wse 3.0 and opened up the config file checked the first checkbox... went to tools and put in user name and password. It asked for a certificate which I dont know why but I put my user certificate in and it did create a policy. Still doesn't seem to work though.


"The content type text/xml; charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 895 bytes of the response were: '<?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><soapenv:Fault><faultcode>soapenv:VersionMismatch</faultcode><faultstring>BEA-382032: The message must be an instance of: {http://schemas.xmlsoap.org/soap/envelope/}Envelope</faultstring><detail><con:fault xmlns:con="http://www.bea.com/wli/sb/context"><con:errorCode>BEA-382032</con:errorCode><con:reason>The message must be an instance of: {http://schemas.xmlsoap.org/soap/envelope/}Envelope</con:reason><con:details><err:InvalidEnvelope xmlns:err="http://www.bea.com/wli/sb/errors"><err:localpart>Envelope</err:localpart><err:namespace>http://www.w3.org/2003/05/soap-envelope</err:namespace></err:InvalidEnvelope></con:details><con:location><con:path>request-pipeline</con:path></con:location></con:fault></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>'."

Open in new window

0
 
LVL 7

Assisted Solution

by:illusio
illusio earned 300 total points
ID: 33744321
Ok - so that proves that your webservice is in running SOAP 1.1 :-)  (basicHttpBinding)
That still leaves your error. I'm sorry but without extended investigation of the service itself I have no more options to guess for the solution.
You better contact the creator of the service you are trying to consume to know what options they additionally need. There is some data you can add to the soap header (all methods for that can be found in the client proxy you successfully created). But without any specification about what they expect, ... it's a wild goose chase.

I'm very sorry - not all answers can be satisfying.

If you the service you are trying to connect to is publicly accessable (which I doubt) and you tell us which one it is, we can provide you quickly the correct response.
0
 
LVL 3

Expert Comment

by:Deepu Sreedhar
ID: 33744699
after setting the policy in the config file, if you can enable tracking in the last tab, it will give you the incoming & outgoing request/response in respective files, which you can use it for finding the fault on outgoing request.
0
 

Author Closing Comment

by:cobolinx1
ID: 33753576
There was a specific security heading that I had to put in the config file. Thanks for your help I was going crazy!!!
0
 
LVL 7

Expert Comment

by:illusio
ID: 33756237
You're welcome.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
These instructions are based on installing Owncloud on your new raspberry pi connected with a usb HDD. What do you need Part A? A Raspberry Pi, model B. A boot SD card for the Raspberry Pi. A usb HDD An Ethernet cable to connect to the lo…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question