Server Did not recognize the value of HTTP Header Soapaction

Asked

Viewed 1,604 times

1

I am trying to implement a webservice of a software called Smartertrack only that I am not succeeding... give me the following error:

Server did not recognize the value of HTTP Header SOAPAction: http://localhost:9996/Services2/svcTickets.asmx?op=CreateTicket.

I have tested directly in the browser and works extremely well.

Sub Execute()
    Dim request As HttpWebRequest = CType(WebRequest.Create("http://localhost:9996/Services2/svcTickets.asmx"), HttpWebRequest)
    request.Method = "POST"
    request.Host = "localhost:9996"
    request.ContentType = "text/xml; charset=utf-8"
    request.Headers.Add("SOAPAction", "http://localhost:9996/Services2/svcTickets.asmx?op=CreateTicket")
    request.Method = "POST"
    Dim soapEnvelopeXml As New XmlDocument()
    soapEnvelopeXml.LoadXml("<?xml version=""1.0"" encoding=""utf-8""?>" & ControlChars.CrLf &
    "<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & ControlChars.CrLf &
    "<soap:Body>" & ControlChars.CrLf &
    "<CreateTicket xmlns=""http://localhost:9996/Services2/svcTickets.asmx"">" & ControlChars.CrLf &
    "<authUserName>admin</authUserName>" & ControlChars.CrLf &
    "<authPassword>teste123</authPassword>" & ControlChars.CrLf &
    "<departmentID>3</departmentID>" & ControlChars.CrLf &
    "<groupId>3</groupId>" & ControlChars.CrLf &
    "<userIdOfAgent>2</userIdOfAgent>" & ControlChars.CrLf &
    "<toAddress>[email protected]</toAddress>" & ControlChars.CrLf &
    "<subject>test</subject>" & ControlChars.CrLf &
    "<body>teste</body>" & ControlChars.CrLf &
    "<isHtml>True</isHtml>" & ControlChars.CrLf &
    "<setWaiting>True</setWaiting>" & ControlChars.CrLf &
    "<sendEmail>True</sendEmail>" & ControlChars.CrLf &
    "</CreateTicket>" & ControlChars.CrLf &
    "</soap:Body>" & ControlChars.CrLf &
    "</soap:Envelope>")
    Using stream As Stream = request.GetRequestStream()
        soapEnvelopeXml.Save(stream)
    End Using
    Using response As WebResponse = request.GetResponse()
        Using rd As New StreamReader(response.GetResponseStream())
            Dim soapResult As String = rd.ReadToEnd()
            Console.WriteLine(soapResult)
        End Using
    End Using
End Sub
  • The error message is clear, you are informing the SOAPAction wrong. Without the WSDL on the question, it is not possible to help you.

  • https://portal.smartertools.com/Services2/svcTickets.asmx?WSDL I have to enter it in the code?

2 answers

0

The problem is because you are giving a wrong value on Header SOAPAction.

The correct value to be informed is contained in WSDL who is consuming, to know a little more about WSDL, see that.

You’re trying to consume the method CreateTicket, to know which the SOAPAction correct for this method, you need to search for this information in the WSDL:

<wsdl:operation name="CreateTicket">
    <soap12:operation soapAction="http://www.smartertools.com/SmarterTrack/Services2/svcTickets.asmx/CreateTicket" style="document"/>
    <wsdl:input>
        <soap12:body use="literal"/>
    </wsdl:input>
    <wsdl:output>
        <soap12:body use="literal"/>
    </wsdl:output>
</wsdl:operation>

Note the value of the attribute soapAction:

http://www.smartertools.com/SmarterTrack/Services2/svcTickets.asmx/CreateTicket

In your code change the value you are assigning to SOAPAction:

of:

request.Headers.Add("SOAPAction", "http://localhost:9996/Services2/svcTickets.asmx?op=CreateTicket")

for:

request.Headers.Add("SOAPAction", "http://localhost:9996/SmarterTrack/Services2/svcTickets.asmx/CreateTicket")

Note: I changed the SOAPAction for the domain you are trying to use: localhost:9996.

  • Still not working, gives the same error unfortunately... as I use the WSDL?

0

Change the header to:

request.Headers.Add("SOAPAction", "http://localhost:9996/Services2/CreateTicket")

You can also use the WEB reference import, which already does all the mapping work of the service you are consuming, you would not need to build XML manually.

To do this, right-click the project: Add > Service Reference > Advanced... > Add Web Reference paste the URL of your service. ASMX or . ASMX? WSDL gives a name (Ex.: Consume) and click Add Reference Then in your code you will be able to call the service by:

Dim Servico As New Consumir.svcTickets
Servico.CreateTicket(parametros)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.