'Cannot communicate with SOAP WCF Service. Bad Gateway

I would like to communicate with a WCF Server, but getting always a (502) Bad Gateway Error.

The supplier is saying:

Here the wsse:Security header is missing. The minimal change needed is adding

    <wsse:Security s:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <wsse:UsernameToken wsu:Id="Id">
        <wsse:Username>TheCorrectUser</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">TheCorrectPassword</wsse:Password>
      </wsse:UsernameToken>
    </wsse:Security>

inside of the "<s:Header></s:Header>" part.

and this is my code:

   ' Set up the binding element 
   Dim strBarCode = "1234567890"
   Dim binding = New WSHttpBinding()
   binding.Name = "POSReceiptPort"
   binding.Security.Mode = SecurityMode.Transport
   binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic
   binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName
   
   Const K_TestClientName As String = "CCCCCCCCC"
   Const K_TestClientPassword As String = "ZZZZZZZZZ"
   Const K_TestEndpoint As String = "https://postest.envipco.com/Malta"
   
   ' Define the endpoint address
   Dim endpointStr = K_TestEndpoint
   Dim endpoint = New EndpointAddress(endpointStr)
   
   'Service
   Dim wsBCRS = New WCF_BCRS.POSReceiptPortClient(binding, endpoint)
   
   'Set Credentisls
   wsBCRS.ClientCredentials.UserName.UserName = K_TestClientName
   wsBCRS.ClientCredentials.UserName.Password = K_TestClientPassword
   
   
   wsBCRS.Open()
   Dim iStatusCode As Integer = 0
   Dim iDeposit As Integer = 0
   Dim z = wsBCRS.Redeem(strBarCode, Nothing, Nothing, iStatusCode, iDeposit)   ' << (502) Bad Gateway
   wsBCRS.Close()

The WSDL is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<definitions name="POSReceiptService"
             targetNamespace="http://www.envipco.com/POSReceiptService.wsdl"
             xmlns:tns="http://www.envipco.com/POSReceiptService.wsdl"
             xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
             xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
             xmlns:HTTP="http://schemas.xmlsoap.org/wsdl/http/"
             xmlns:MIME="http://schemas.xmlsoap.org/wsdl/mime/"
             xmlns:DIME="http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/"
             xmlns:WSDL="http://schemas.xmlsoap.org/wsdl/"
             xmlns="http://schemas.xmlsoap.org/wsdl/">
  <types>
    <schema targetNamespace="http://www.envipco.com/POSReceiptService.wsdl"
            xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
            xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://www.w3.org/2001/XMLSchema">
      <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
    </schema>
  </types>

  <message name="StatusResponse">
    <part name="statusText" type="xsd:string"/>
    <part name="httpStatusCode" type="xsd:int"/>
  </message>

  <message name="PosResponse">
    <part name="statusText" type="xsd:string"/>
    <part name="httpStatusCode" type="xsd:int"/>
    <part name="deposit" type="xsd:int"/>
  </message>

  <message name="RemoveBCRequest">
    <part name="barcode" type="xsd:string"/>
    <part name="id" type="xsd:int"/>
  </message>

  <message name="AddReceiptRequest">
    <part name="barcode" type="xsd:string"/>
    <part name="store" type="xsd:string"/>
    <part name="rvm" type="xsd:string"/>
    <part name="deposit" type="xsd:int"/>
  </message>

  <message name="AddReceipt2Request">
    <part name="barcode" type="xsd:string"/>
    <part name="store" type="xsd:string"/>
    <part name="chain" type="xsd:string"/>
    <part name="rvm" type="xsd:string"/>
    <part name="deposit" type="xsd:int"/>
  </message>

  <message name="LockRequest">
    <part name="barcode" type="xsd:string"/>
    <part name="POS" type="xsd:string"/>
    <part name="store" type="xsd:string"/>
  </message>

  <message name="RedeemRequest">
    <part name="barcode" type="xsd:string"/>
    <part name="POS" type="xsd:string"/>
    <part name="store" type="xsd:string"/>
  </message>

  <message name="Redeem2Request">
    <part name="barcode" type="xsd:string"/>
    <part name="POS" type="xsd:string"/>
    <part name="store" type="xsd:string"/>
    <part name="chain" type="xsd:string"/>
  </message>

  <message name="PingRequest">
  </message>

  <message name="PingResponse">
    <part name="response" type="xsd:int"/>
  </message>

  <portType name="POSReceiptPort">
    <operation name="AddReceipt">
      <input message="tns:AddReceiptRequest"/>
      <output message="tns:StatusResponse"/>
    </operation>
    <operation name="AddReceipt2">
      <input message="tns:AddReceipt2Request"/>
      <output message="tns:StatusResponse"/>
    </operation>
    <operation name="RemoveBC">
      <input message="tns:RemoveBCRequest"/>
      <output message="tns:StatusResponse"/>
    </operation>
    <operation name="Lock">
      <input message="tns:LockRequest"/>
      <output message="tns:PosResponse"/>
    </operation>
    <operation name="Redeem">
      <input message="tns:RedeemRequest"/>
      <output message="tns:PosResponse"/>
    </operation>
    <operation name="Redeem2">
      <input message="tns:Redeem2Request"/>
      <output message="tns:PosResponse"/>
    </operation>
    <operation name="Ping">
      <input message="tns:PingRequest"/>
      <output message="tns:PingResponse"/>
    </operation>
  </portType>

  <binding name="POSReceiptBinding" type="tns:POSReceiptPort">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="RemoveBC">
      <soap:operation soapAction=""/>
      <input>
        <soap:body use="literal" namespace="http://www.envipco.com/POSReceiptService.wsdl"/>
      </input>
      <output>
        <soap:body use="literal" namespace="http://www.envipco.com/POSReceiptService.wsdl"/>
      </output>
    </operation>
    <operation name="AddReceipt">
      <soap:operation soapAction=""/>
      <input>
        <soap:body use="literal" namespace="http://www.envipco.com/POSReceiptService.wsdl"/>
      </input>
      <output>
        <soap:body use="literal" namespace="http://www.envipco.com/POSReceiptService.wsdl"/>
      </output>
    </operation>
    <operation name="AddReceipt2">
      <soap:operation soapAction=""/>
      <input>
        <soap:body use="literal" namespace="http://www.envipco.com/POSReceiptService.wsdl"/>
      </input>
      <output>
        <soap:body use="literal" namespace="http://www.envipco.com/POSReceiptService.wsdl"/>
      </output>
    </operation>
    <operation name="Lock">
      <soap:operation style="rpc" soapAction=""/>
      <input>
        <soap:body use="literal" namespace="http://www.envipco.com/POSReceiptService.wsdl"/>
      </input>
      <output>
        <soap:body use="literal" namespace="http://www.envipco.com/POSReceiptService.wsdl"/>
      </output>
    </operation>
    <operation name="Redeem">
      <soap:operation style="rpc" soapAction=""/>
      <input>
        <soap:body use="literal" namespace="http://www.envipco.com/POSReceiptService.wsdl"/>
      </input>
      <output>
        <soap:body use="literal" namespace="http://www.envipco.com/POSReceiptService.wsdl"/>
      </output>
    </operation>
    <operation name="Redeem2">
      <soap:operation style="rpc" soapAction=""/>
      <input>
        <soap:body use="literal" namespace="http://www.envipco.com/POSReceiptService.wsdl"/>
      </input>
      <output>
        <soap:body use="literal" namespace="http://www.envipco.com/POSReceiptService.wsdl"/>
      </output>
    </operation>
    <operation name="Ping">
      <soap:operation style="rpc" soapAction=""/>
      <input>
        <soap:body use="literal" namespace="http://www.envipco.com/POSReceiptService.wsdl"/>
      </input>
      <output>
        <soap:body use="literal" namespace="http://www.envipco.com/POSReceiptService.wsdl"/>
      </output>
    </operation>
  </binding>

  <service name="POSReceiptService">
    <documentation>WSDL file for communication to the POS receipt server</documentation>
    <port binding="tns:POSReceiptBinding" name="POSReceiptPort">
      <soap:address location="https://posserver.envipco.com/POSImporter/"/>
    </port>
  </service>
</definitions>

Can someone please tell me what I'm doing wrong? JP



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source