Solved

Call webservice from vb.net

Posted on 2010-09-22
20
1,647 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
  • 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 74

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
 

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 74

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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:deepusreedhar
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:
deepusreedhar 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:deepusreedhar
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now