Question Retrieving data using a supplied WSDL

taggart

Member
Joined
Nov 2, 2015
Messages
10
Programming Experience
10+
Hello forum
This is my first post and I hope you guys can help.

I am a vb.net programmer but I'm new to web services. I've been given a WSDL from a third party which contains many function calls but I'm only interested in one. The 'CreateShipment' takes one input parameter (WSDL message 'CreateShipmentRequest') and responds with one output parameter (WSDL message 'CreateShipmentReply'). The input parameter is actually an xml file.

I've successfully imported the WSDL into my vb.net project as a web reference and the vb intellisense can see functions inside the WSDL.
There is lots of discussion on the web regarding creating SOAP wrappers but I am hoping that .net will handle all that stuff and all I will have to do pass the xml as a string into the 'CreateShipmentRequest' call and receive the response via 'CreateShipmentReply'

Am I being naive as I can't see any way of passing the xml string into CreateShipmentRequest.

Any help would be much appreciated.

I've included the relevant parts of the WSDL at the bottom of this post.
note I've named the imported WSDL web reference as 'webservice'

My attempt so far...

Dim myxml as string 'this will contain an xml string. not used in code below as i cant see how to pass it in

Dim MyService As webservice.ShipService = New webservice.ShipService 'name of the service as specified at the bottom of the WSDL


Dim myresult As webservice.CreateShipmentReply


Dim myrequest As webservice.CreateShipmentRequest = New webservice.CreateShipmentRequest


myresult = MyService.createShipment(myrequest)


There are no intellisense errors but I can't see how to pass the xml string into CreateShipmentRequest.


Relevant parts of the WSDL...

<?xml version="1.0" encoding="UTF-8"?>
<definitions
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:s1="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:ns="http://www.thirdparty.net/ws/ship/v1"
targetNamespace="http://www.thirdparty.net/ws/ship/v1"
name="ShipServiceDefinitions">


<types>
<xs:schema
attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://www.thirdparty.net/ws/ship/v1"
xmlns:ns="http://www.thirdparty.net/ws/ship/v1"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="CreateShipmentRequest" type="ns:CreateShipmentRequest"/>
<xs:element name="CreateShipmentReply" type="ns:CreateShipmentReply"/>
...etc

<xs:complexType name="CreateShipmentRequest">
<xs:complexContent>
<xs:extension base="ns:BaseRequest">
<xs:sequence>
<xs:element name="RequestedShipment" type="ns:RequestedShipment"></xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="CreateShipmentReply">
<xs:complexContent>
<xs:extension base="ns:BaseReply">
<xs:sequence>
<xs:element name="CompletedShipmentInfo" type="ns:CompletedShipmentInfo"></xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
...etc

<message name="CreateShipmentRequest">
<part name="CreateShipmentRequest" element="ns:CreateShipmentRequest"/>
</message>
<message name="CreateShipmentReply">
<part name="CreateShipmentReply" element="ns:CreateShipmentReply"/>
</message>
...etc

<portType name="ShipPortType">
<operation name="createShipment" parameterOrder="CreateShipmentRequest">
<input message="ns:CreateShipmentRequest"/>
<output message="ns:CreateShipmentReply"/>
</operation>
...etc

<binding name="ShipServiceSoapBinding" type="ns:ShipPortType">
<s1:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="createShipment">
<s1:eek:peration soapAction="createShipment" style="document"/>
<input>
<s1:body use="literal"/>
</input>
<output>
<s1:body use="literal"/>
</output>
</operation>
...etc

<service name="ShipService">
<port name="ShipServicePort" binding="ns:ShipServiceSoapBinding">
<s1:address location="https://exact.thirdparty.net/ws/"/>
</port>
</service>
 
CreateShipmentRequest should have properties that you can set values for. (myrequest.SomeProperty = some value/object)
 
CreateShipmentRequest should have properties that you can set values for. (myrequest.SomeProperty = some value/object)

Thanks for the reply. I guess the property should be defined in the WSDL but I don't know enough about WSDL construction to know where to look.
 
No need to read WSDL, write code "myrequest." and see what intellisense comes up with. You can also review CreateShipmentRequest type in Object Browser in VS.
 
Thanks, I think I'm getting somewhere. There are two classes with properties and sub classes/properties that I can set. Looks like i need to extract the property details from the test xml input file and populate each of the properties independently. Looks promising. I thought it was too simple to just throw the test xml file at the CreateShipmentRequest routine.
 
It is possible one of the properties expects a string that has xml data, but normally when interacting with web services xml is just part of the underlying communications that the proxy takes care of.
I've successfully imported the WSDL into my vb.net project as a web reference
'web reference' is part of old .Net 2.0 technology that they have tried to hide as best they can (that they haven't removed it could mean it has legacy uses still), in VS 2008-2015 you should add 'service reference' also for soap services, this uses the newer WCF technology. Using the proxy is pretty much the same.
 
I've changed it from Web Service to Service Reference and it now doesn't like

Dim MyService As webservice.ShipService = New webservice.ShipService

Its as though shipservice is inherent which is fine but then I can't do

myresult = MyService.createShipment(myrequest)

as Myservice is not defined and createShipment is no longer in intellisense. I'm back to not being able to pass in myrequest properties.
 
The names of namespace, type and maybe it's members will be slightly different for web reference, standard namespace is 'WebReference1' if you didn't change it. The type ShipService will typically be a "...Client" type in WCF, and I think they put "Soap" in there too if the service is a SOAP service, so it may be "ShipSoapClient" if I had to guess. It should be easy to discover by intellisense in code or Object Browser.
 
Thanks. I got it after a bit of trial and errror. It's actually ShipPortTypeClient. I think my code should now work but I'm getting a 'Server returned an invalid SOAP Fault' error. Looking at other forums, It seems there may be a fault with the WCF implementation of the returned SOAP fault code parameters. I may have to revert back to Web Service rather than Service Reference as there is some indication that the 'old school' implementation is not so fussy.
 
All working now. I did spend about 30 mins posting my code example and WSDL code with full axplanation and a thank you to the forum but the quick reply deleted most of it as it must only allow limited space. If I get chance later I will try again.
 
You can view the request/response with Fiddler or similar web debugging tool.
 
Back
Top