Solved

Call webservice from vb.net

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

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

914 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

18 Experts available now in Live!

Get 1:1 Help Now