我试图通过名为SmarterTrack的软件实施网络服务,只是因为我没有得到它...给我以下错误:
服务器无法识别HTTP标头SOAPAction的值:http://localhost:9996/Services2/svcTickets.asmx?op=CreateTicket。
我已经在浏览器中直接测试了它,效果非常好。
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>teste@teste.pt</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
我将以下wsdl直接导入到visual studio中作为服务引用,只是模拟了域。我做得对吗? http://portal.smartertools.com/Services2/svcTickets.asmx?WSDL
答案 0 :(得分:0)
查看此页http://portal.smartertools.com/Services2/svcTickets.asmx?op=CreateTicket时,您可以看到示例请求。请注意?op=CreateTicket
作为此测试表单的参数。
阅读同一页面,你会看到这个例子:
SOAPAction: "http://www.smartertools.com/SmarterTrack/Services2/svcTickets.asmx/CreateTicket"
这是您必须将SOAPAction标头发送到请求中的值(可能是修改后的主机)。
您在演示中提供了带?op=CreateTicket
的测试表单的网址,但这不是SOAPAction。
将SOAPAction视为独立识别与操作本身的URL无关的操作。即使它是从.NET Web服务中的这个URL派生的。