Search code examples
asp.netxmlvb.netwsdlwebmethod

Using a third party web service in vb.net


I am trying to build an app in VS Pro 2012 (VB.NET) that will invoke RoyalMail's MailMark WSDL which has methods such as RetrieveActiveSupplyChains which are expecting a single parameter (request).

I have used svcutil with the /l:vb switch to download the WSDL and referenced it in my project and I can see methods being exposed once I have done

    Dim client As PosterUploadClient = New PosterUploadClient()

Now typing client. brings up all the methods I expect to see and I can pass authentication and see the state change when I do client.open() but what I can't figure out is how to provide the parameters the actual methods need. According to their documentation, RetrieveActiveSupplyChains doesn't need a parameter but they have provided an xml example of the request structure so my assumption is that I'd need to construct this as xml with the appropriate values and send it as "request"?

Does this sound right? I know this is probably meat and veg for a web programmer but not something I have attempted before. The xml they supplied as an example looks like the below:

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
  <s:Header>
    <a:Action s:mustUnderstand="1">http://rm-manifest.com/2014/01/service/IPosterUpload/RetrieveAllActiveSupplyChains</a:Action>
    <a:MessageID>urn:uuid:ab5e32a3-812e-4d91-97a8-de00a08874e9</a:MessageID>
    <a:ReplyTo>
      <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
    </a:ReplyTo>
    <a:To s:mustUnderstand="1">https://rm-manifest.com/PosterUpload2/PosterUpload.svc/service</a:To>
    <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <u:Timestamp u:Id="_0">
        <u:Created>2014-10-03T14:32:58.480Z</u:Created>
        <u:Expires>2014-10-03T14:37:58.480Z</u:Expires>
      </u:Timestamp>
      <o:UsernameToken u:Id="uuid-dfaaf0b0-3823-4f75-b607-33f7434295dc-1">
        <o:Username>NetworkAccess</o:Username>
        <o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">p1</o:Password>
      </o:UsernameToken>
    </o:Security>
  </s:Header>
  <s:Body>
    <RetrieveAllActiveSupplyChains xmlns="http://rm-manifest.com/2014/01/service">
      <request xmlns:b="http://rm-manifest.com/2014/01/messages" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/>
    </RetrieveAllActiveSupplyChains>
  </s:Body>
</s:Envelope>

But I'm still not sure how it actually needs to be submitted, certainly if I read that sample one in with a new xmltextreader it doesn't like it with the following error message

Value of type 'System.Xml.XmlTextReader' cannot be converted to 'MM_TEST.Mosaic.EIB.PosterUploadService.Core.Messages.RetrieveActiveSupplyChainsRequest'

My assumption was the WSDL replaces the need to actually create a "New HttpRequest" in my code but not sure. I've done a lot of googling but not getting anything that quite works like this

The WSDL is here if this helps: https://customertest.rm-manifest.com/PosterUpload/PosterUpload.svc


Solution

  • Just call the method. The provided XML is what is actually sent to the server by the WCF proxy when you call the method. You don't need to use it at all.

    If you use a tool like Fiddler, you'll see that simply calling client.RetrieveAllActiveSupplyChains will send an HTTP request with a body similar to the XML sample.

    In fact, everything outside the RetrieveAllActiveSupplyChains tag isn't related to the method at all - it's security and addressing data used to establish and execute a connection with a web service in general. All of this is handled by WCF.