0
votes

I have this WSDL that is supposed to be used for inbound/outbound messages within an IIS server. I've generated a .vb file using "wsdl thefile.wsdl /l:VB" but now I'm unsure what to do. I'm only supposed to code a method to save inbound messages.

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://www.softwriters.com/fwhl7/1.0/"
xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://www.softwriters.com/fwhl7/1.0/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
 <wsdl:types>
 <s:schema elementFormDefault="qualified" targetNamespace="http://www.softwriters.com/fwhl7/1.0/">
 <s:element name="SendMessage">
 <s:complexType>
 <s:sequence>
 <s:element minOccurs="0" maxOccurs="1" name="userId" type="s:string" />
 <s:element minOccurs="0" maxOccurs="1" name="passwordDigest" type="s:base64Binary" />
 <s:element minOccurs="0" maxOccurs="1" name="nonce" type="s:string" />
 <s:element minOccurs="1" maxOccurs="1" name="ts" type="s:dateTime" />
 <s:element minOccurs="0" maxOccurs="1" name="message" type="s:base64Binary" />
 </s:sequence>
 </s:complexType>
 </s:element>
 <s:element name="SendMessageResponse">
 <s:complexType>
 <s:sequence>
 <s:element minOccurs="0" maxOccurs="1" name="SendMessageResult" type="s:base64Binary" />
 </s:sequence>
 </s:complexType>
 </s:element>
 </s:schema>
 </wsdl:types>
 <wsdl:message name="SendMessageSoapIn">
 <wsdl:part name="parameters" element="tns:SendMessage" />
 </wsdl:message>
 <wsdl:message name="SendMessageSoapOut">
 <wsdl:part name="parameters" element="tns:SendMessageResponse" />
 </wsdl:message>
 <wsdl:portType name="FwHL7Soap">
 <wsdl:operation name="SendMessage">
 <wsdl:input message="tns:SendMessageSoapIn" />
 <wsdl:output message="tns:SendMessageSoapOut" />
 </wsdl:operation>
 </wsdl:portType>
 <wsdl:binding name="FwHL7Soap" type="tns:FwHL7Soap">
 <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
 <wsdl:operation name="SendMessage">
 <soap:operation soapAction="http://www.softwriters.com/fwhl7/1.0/SendMessage" style="document" />
 <wsdl:input>
 <soap:body use="literal" />
 </wsdl:input>
  <wsdl:output>
 <soap:body use="literal" />
 </wsdl:output>
 </wsdl:operation>
 </wsdl:binding>
 <wsdl:binding name="FwHL7Soap12" type="tns:FwHL7Soap">
 <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
 <wsdl:operation name="SendMessage">
 <soap12:operation soapAction="http://www.softwriters.com/fwhl7/1.0/SendMessage" style="document" />
 <wsdl:input>
 <soap12:body use="literal" />
 </wsdl:input>
 <wsdl:output>
 <soap12:body use="literal" />
 </wsdl:output>
 </wsdl:operation>
 </wsdl:binding>
 <wsdl:service name="FwHL7">
 <wsdl:port name="FwHL7Soap" binding="tns:FwHL7Soap">
 <soap:address location="http://localhost:53012/FwHL7.asmx" />
 </wsdl:port>
 <wsdl:port name="FwHL7Soap12" binding="tns:FwHL7Soap12">
 <soap12:address location="http://localhost:53012/FwHL7.asmx" />
 </wsdl:port>
 </wsdl:service>
</wsdl:definitions>

I've created a new ASP.NET web service project, added the WSDL to the service references, and imported the generated .vb. I've created a ASMX file within the project but am unsure where to go from there. Looking at the interface, I'm assuming I should add WebMethod() to the applicable methods:

Option Strict Off
Option Explicit On
'------------------------------------------------------------------------------
' <auto-generated>
'     This code was generated by a tool.
'     Runtime Version:4.0.30319.42000
'
'     Changes to this file may cause incorrect behavior and will be lost if
'     the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------

Imports System.Web.Services

<System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0"),
 System.ServiceModel.ServiceContractAttribute([Namespace]:="http://www.softwriters.com/fwhl7/1.0/", ConfigurationName:="FwHL7Soap")>
Public Interface FwHL7Soap

    'CODEGEN: Generating message contract since element name userId from namespace http://www.softwriters.com/fwhl7/1.0/ is not marked nillable
    <System.ServiceModel.OperationContractAttribute(Action:="http://www.softwriters.com/fwhl7/1.0/SendMessage", ReplyAction:="*")>
    Function SendMessage(ByVal request As SendMessageRequest) As SendMessageResponse

    <System.ServiceModel.OperationContractAttribute(Action:="http://www.softwriters.com/fwhl7/1.0/SendMessage", ReplyAction:="*")>
    Function SendMessageAsync(ByVal request As SendMessageRequest) As System.Threading.Tasks.Task(Of SendMessageResponse)
End Interface

<System.Diagnostics.DebuggerStepThroughAttribute(),
 System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0"),
 System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced),
 System.ServiceModel.MessageContractAttribute(IsWrapped:=False)>
Partial Public Class SendMessageRequest

    <System.ServiceModel.MessageBodyMemberAttribute(Name:="SendMessage", [Namespace]:="http://www.softwriters.com/fwhl7/1.0/", Order:=0)>
    Public Body As SendMessageRequestBody

    Public Sub New()
        MyBase.New
    End Sub

    Public Sub New(ByVal Body As SendMessageRequestBody)
        MyBase.New
        Me.Body = Body
    End Sub
End Class

<System.Diagnostics.DebuggerStepThroughAttribute(),
 System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0"),
 System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced),
 System.Runtime.Serialization.DataContractAttribute([Namespace]:="http://www.softwriters.com/fwhl7/1.0/")>
Partial Public Class SendMessageRequestBody

    <System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue:=False, Order:=0)>
    Public userId As String

    <System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue:=False, Order:=1)>
    Public passwordDigest() As Byte

    <System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue:=False, Order:=2)>
    Public nonce As String

    <System.Runtime.Serialization.DataMemberAttribute(Order:=3)>
    Public ts As Date

    <System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue:=False, Order:=4)>
    Public message() As Byte

    Public Sub New()
        MyBase.New
    End Sub

    Public Sub New(ByVal userId As String, ByVal passwordDigest() As Byte, ByVal nonce As String, ByVal ts As Date, ByVal message() As Byte)
        MyBase.New
        Me.userId = userId
        Me.passwordDigest = passwordDigest
        Me.nonce = nonce
        Me.ts = ts
        Me.message = message
    End Sub
End Class

<System.Diagnostics.DebuggerStepThroughAttribute(),
 System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0"),
 System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced),
 System.ServiceModel.MessageContractAttribute(IsWrapped:=False)>
Partial Public Class SendMessageResponse

    <System.ServiceModel.MessageBodyMemberAttribute(Name:="SendMessageResponse", [Namespace]:="http://www.softwriters.com/fwhl7/1.0/", Order:=0)>
    Public Body As SendMessageResponseBody

    Public Sub New()
        MyBase.New
    End Sub

    Public Sub New(ByVal Body As SendMessageResponseBody)
        MyBase.New
        Me.Body = Body

    End Sub
End Class

<System.Diagnostics.DebuggerStepThroughAttribute(),
 System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0"),
 System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced),
 System.Runtime.Serialization.DataContractAttribute([Namespace]:="http://www.softwriters.com/fwhl7/1.0/")>
Partial Public Class SendMessageResponseBody

    <System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue:=False, Order:=0)>
    Public SendMessageResult() As Byte

    Public Sub New()
        MyBase.New
    End Sub

    Public Sub New(ByVal SendMessageResult() As Byte)
        MyBase.New
        Me.SendMessageResult = SendMessageResult
    End Sub
End Class

<System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")>
Public Interface FwHL7SoapChannel
    Inherits FwHL7Soap, System.ServiceModel.IClientChannel
End Interface

<System.Diagnostics.DebuggerStepThroughAttribute(),
 System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")>
Partial Public Class FwHL7SoapClient
    Inherits System.ServiceModel.ClientBase(Of FwHL7Soap)
    Implements FwHL7Soap

    Public Sub New()
        MyBase.New
    End Sub

    Public Sub New(ByVal endpointConfigurationName As String)
        MyBase.New(endpointConfigurationName)
    End Sub

    Public Sub New(ByVal endpointConfigurationName As String, ByVal remoteAddress As String)
        MyBase.New(endpointConfigurationName, remoteAddress)
    End Sub

    Public Sub New(ByVal endpointConfigurationName As String, ByVal remoteAddress As System.ServiceModel.EndpointAddress)
        MyBase.New(endpointConfigurationName, remoteAddress)
    End Sub

    Public Sub New(ByVal binding As System.ServiceModel.Channels.Binding, ByVal remoteAddress As System.ServiceModel.EndpointAddress)
        MyBase.New(binding, remoteAddress)
    End Sub

    <System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)>
    Function FwHL7Soap_SendMessage(ByVal request As SendMessageRequest) As SendMessageResponse Implements FwHL7Soap.SendMessage
        Return MyBase.Channel.SendMessage(request)
    End Function

    <WebMethod()>
    Public Function SendMessage(ByVal userId As String, ByVal passwordDigest() As Byte, ByVal nonce As String, ByVal ts As Date, ByVal message() As Byte) As Byte()
        Dim inValue As SendMessageRequest = New SendMessageRequest()
        inValue.Body = New SendMessageRequestBody()
        inValue.Body.userId = userId
        inValue.Body.passwordDigest = passwordDigest
        inValue.Body.nonce = nonce
        inValue.Body.ts = ts
        inValue.Body.message = message
        Dim retVal As SendMessageResponse = CType(Me, FwHL7Soap).SendMessage(inValue)
        Return retVal.Body.SendMessageResult
    End Function

    <WebMethod()>
    <System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)>
    Function FwHL7Soap_SendMessageAsync(ByVal request As SendMessageRequest) As System.Threading.Tasks.Task(Of SendMessageResponse) Implements FwHL7Soap.SendMessageAsync
        Return MyBase.Channel.SendMessageAsync(request)
    End Function

    <WebMethod()>
    Public Function SendMessageAsync(ByVal userId As String, ByVal passwordDigest() As Byte, ByVal nonce As String, ByVal ts As Date, ByVal message() As Byte) As System.Threading.Tasks.Task(Of SendMessageResponse)
        Dim inValue As SendMessageRequest = New SendMessageRequest()
        inValue.Body = New SendMessageRequestBody()
        inValue.Body.userId = userId
        inValue.Body.passwordDigest = passwordDigest
        inValue.Body.nonce = nonce
        inValue.Body.ts = ts
        inValue.Body.message = message
        Return CType(Me, FwHL7Soap).SendMessageAsync(inValue)
    End Function
End Class
1

1 Answers

2
votes

I'd comment to ask for clarification, but I'm 2 reputation short of being able to do that.

Instead, I will make some assumptions.

Assumption 1 - You don't have access to the web service that the wsdl was generated from.

Assumption 2 - You are building a client that will invoke the web service, and will track all calls through the client.

Assumption 3 - You are using Visual Studio.

If I am incorrect in my assumptions, feel free to comment and I will edit my answer to be more in line with your question.

With that out of the way, all the vb code that was generated from wsdl is unnecessary and will just bloat your project.

Instead, since you have added the wsdl as a service reference, you can directly invoke the web service from a method in your application. When a service reference is added, all the web methods are accessible by your project, as if the service is a class you have added. From the wsdl you linked, it looks like the SendMessage method is the one you want to use.

Public Sub SendMyMessage()
    Dim password As New Byte 
    Dim userId As String = "MyUserId"
    Dim nonce As String = "I'm not sure what this is"
    Dim ts As Date = Date.Now 'I initialized this with the current date
    Dim message As New Byte 'This is your message
    Dim webservice As New FwHL7 'This would be the name of your web service reference
    Dim response = webservice.SendMessage(userId, password, nonce, ts, message) 'This is where you actually invoke the webservice and load its response into a variable
End Sub

From there, just add code to log the message.