Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1726
  • Last Modified:

Call webservice from vb.net

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
cobolinx1
Asked:
cobolinx1
  • 9
  • 5
  • 3
  • +2
4 Solutions
 
illusioCommented:
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
 
käµfm³d 👽Commented:
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
 
roxviperCommented:
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
cobolinx1Author Commented:
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
 
cobolinx1Author Commented:
I have a username and password if it needs it but how would I add it?
0
 
cobolinx1Author Commented:
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
 
käµfm³d 👽Commented:
Does your web service require certificate authentication?
0
 
cobolinx1Author Commented:
It looks like its just looking for the security token username and password... isn't that the same as the client credentials?
0
 
cobolinx1Author Commented:
No I confirmed it doesn't require certificate authentication.
0
 
illusioCommented:

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
 
cobolinx1Author Commented:
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
 
cobolinx1Author Commented:
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
 
Deepu SreedharBI Software EngineerCommented:
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
 
Deepu SreedharBI Software EngineerCommented:
See the picture attached. and let me know if you need more help on this.
WSE.JPG
0
 
illusioCommented:
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
 
cobolinx1Author Commented:
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
 
illusioCommented:
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
 
Deepu SreedharBI Software EngineerCommented:
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
 
cobolinx1Author Commented:
There was a specific security heading that I had to put in the config file. Thanks for your help I was going crazy!!!
0
 
illusioCommented:
You're welcome.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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