DotNet WS from VB6 with MSXML2.XMLHTTP

B

BjörnHolmberg

I'm trying to consume a WS from Excel (Office 98), seems that I can't
send arguments into the WS. In order to pinpoint the problem I've
written the following application i C# and VB6. It reproduces exaclty
the same problem with less code. Any hints on how to solve this would be
greatly appreciated. /Regards Björn

The webservice is:

using System;
using System.Web.Services;

[WebService(Namespace="http://tempuri.org/")]
public class DotNetWS : WebService {
[WebMethod]
public string ReturnArgument(string Argument) {
return Argument;
//return "We can't get Argument into WS!";
}
}

And this is the client:

Private Sub Command1_Click()
Dim mhttp As MSXML2.XMLHTTP
Dim s As String

Set mhttp = New MSXML2.XMLHTTP
mhttp.open "Post", "http://localhost/DotNetWS/DotNetWS.asmx", False
mhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
mhttp.setRequestHeader "SoapAction",
"http://tempuri.org/ReturnArgument"

s = s & "<?xml version=""1.0"" encoding=""UTF-8""?>"
s = s & "<soap:Envelope
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" "
s = s & "xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" "
s = s & "xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">"
s = s & "<soap:Body>"
s = s & "<ReturnArgument xmlns=""http://tempuri.org"">"
s = s & "<Argument>Easy go, easy come back?</Argument>"
s = s & "</ReturnArgument>"
s = s & "</soap:Body>"
s = s & "</soap:Envelope>"

mhttp.send s
MsgBox mhttp.responseText
End Sub
 
K

Ken Cox [Microsoft MVP]

Hi Björn,
I was able to make it work with a few adjustments. You'll need to change the
URL and the namespaces that are for my system:

Private Sub Command1_Click()
Dim mhttp As MSXML2.XMLHTTP
Dim s As String
Set mhttp = CreateObject("MSXML2.XMLHTTP")
mhttp.Open _
"POST", "http://p4320/p4320work/args.asmx", False, "", ""
mhttp.setRequestHeader "SOAPAction", _
"http://tempuri.org/p4320work/args/ReturnArgument"
mhttp.setRequestHeader "Content-Type", "text/xml"
s = s & "<?xml version=""1.0"" encoding=""UTF-8""?>"
s = s & "<soap:Envelope
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" "
s = s & "xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" "
s = s & "xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">"
s = s & "<soap:Body>"
s = s & "<ReturnArgument xmlns=""http://tempuri.org/p4320work/args"">"
s = s & "<Argument>Easy go, easy come back?</Argument>"
s = s & "</ReturnArgument>"
s = s & "</soap:Body>"
s = s & "</soap:Envelope>"
mhttp.send s
Debug.Print mhttp.responseText
End Sub
 
B

BjörnHolmberg

Hello Ken! I've found the problem, it was a trailing slash in the namespace declaration of WS, that
was not in the <ReturnArgument>-element of client. A bunch of thanks to You, without your reply I
would still be out in the (be-)wilderness. /Björn

Ken Cox said:
Hi Björn,
I was able to make it work with a few adjustments. You'll need to change the
URL and the namespaces that are for my system:

Private Sub Command1_Click()
Dim mhttp As MSXML2.XMLHTTP
Dim s As String
Set mhttp = CreateObject("MSXML2.XMLHTTP")
mhttp.Open _
"POST", "http://p4320/p4320work/args.asmx", False, "", ""
mhttp.setRequestHeader "SOAPAction", _
"http://tempuri.org/p4320work/args/ReturnArgument"
mhttp.setRequestHeader "Content-Type", "text/xml"
s = s & "<?xml version=""1.0"" encoding=""UTF-8""?>"
s = s & "<soap:Envelope
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" "
s = s & "xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" "
s = s & "xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">"
s = s & "<soap:Body>"
s = s & "<ReturnArgument xmlns=""http://tempuri.org/p4320work/args"">"
s = s & "<Argument>Easy go, easy come back?</Argument>"
s = s & "</ReturnArgument>"
s = s & "</soap:Body>"
s = s & "</soap:Envelope>"
mhttp.send s
Debug.Print mhttp.responseText
End Sub

BjörnHolmberg said:
I'm trying to consume a WS from Excel (Office 98), seems that I can't
send arguments into the WS. In order to pinpoint the problem I've
written the following application i C# and VB6. It reproduces exaclty
the same problem with less code. Any hints on how to solve this would be
greatly appreciated. /Regards Björn

The webservice is:

using System;
using System.Web.Services;

[WebService(Namespace="http://tempuri.org/")]
public class DotNetWS : WebService {
[WebMethod]
public string ReturnArgument(string Argument) {
return Argument;
//return "We can't get Argument into WS!";
}
}

And this is the client:

Private Sub Command1_Click()
Dim mhttp As MSXML2.XMLHTTP
Dim s As String

Set mhttp = New MSXML2.XMLHTTP
mhttp.open "Post", "http://localhost/DotNetWS/DotNetWS.asmx", False
mhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
mhttp.setRequestHeader "SoapAction",
"http://tempuri.org/ReturnArgument"

s = s & "<?xml version=""1.0"" encoding=""UTF-8""?>"
s = s & "<soap:Envelope
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" "
s = s & "xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" "
s = s & "xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">"
s = s & "<soap:Body>"
s = s & "<ReturnArgument xmlns=""http://tempuri.org"">"
s = s & "<Argument>Easy go, easy come back?</Argument>"
s = s & "</ReturnArgument>"
s = s & "</soap:Body>"
s = s & "</soap:Envelope>"

mhttp.send s
MsgBox mhttp.responseText
End Sub
 
K

Ken Cox [Microsoft MVP]

Hi Björn,

Glad to hear you're running again!

Why don't computers tell us when we're missing something simple - or better
yet, just fix it? <grin>

Ken

BjörnHolmberg said:
Hello Ken! I've found the problem, it was a trailing slash in the
namespace declaration of WS, that
was not in the <ReturnArgument>-element of client. A bunch of thanks to
You, without your reply I
would still be out in the (be-)wilderness. /Björn

Ken Cox said:
Hi Björn,
I was able to make it work with a few adjustments. You'll need to change
the
URL and the namespaces that are for my system:

Private Sub Command1_Click()
Dim mhttp As MSXML2.XMLHTTP
Dim s As String
Set mhttp = CreateObject("MSXML2.XMLHTTP")
mhttp.Open _
"POST", "http://p4320/p4320work/args.asmx", False, "", ""
mhttp.setRequestHeader "SOAPAction", _
"http://tempuri.org/p4320work/args/ReturnArgument"
mhttp.setRequestHeader "Content-Type", "text/xml"
s = s & "<?xml version=""1.0"" encoding=""UTF-8""?>"
s = s & "<soap:Envelope
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" "
s = s & "xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" "
s = s & "xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">"
s = s & "<soap:Body>"
s = s & "<ReturnArgument xmlns=""http://tempuri.org/p4320work/args"">"
s = s & "<Argument>Easy go, easy come back?</Argument>"
s = s & "</ReturnArgument>"
s = s & "</soap:Body>"
s = s & "</soap:Envelope>"
mhttp.send s
Debug.Print mhttp.responseText
End Sub

message
I'm trying to consume a WS from Excel (Office 98), seems that I can't
send arguments into the WS. In order to pinpoint the problem I've
written the following application i C# and VB6. It reproduces exaclty
the same problem with less code. Any hints on how to solve this would
be
greatly appreciated. /Regards Björn

The webservice is:

using System;
using System.Web.Services;

[WebService(Namespace="http://tempuri.org/")]
public class DotNetWS : WebService {
[WebMethod]
public string ReturnArgument(string Argument) {
return Argument;
//return "We can't get Argument into WS!";
}
}

And this is the client:

Private Sub Command1_Click()
Dim mhttp As MSXML2.XMLHTTP
Dim s As String

Set mhttp = New MSXML2.XMLHTTP
mhttp.open "Post", "http://localhost/DotNetWS/DotNetWS.asmx", False
mhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
mhttp.setRequestHeader "SoapAction",
"http://tempuri.org/ReturnArgument"

s = s & "<?xml version=""1.0"" encoding=""UTF-8""?>"
s = s & "<soap:Envelope
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" "
s = s & "xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" "
s = s & "xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">"
s = s & "<soap:Body>"
s = s & "<ReturnArgument xmlns=""http://tempuri.org"">"
s = s & "<Argument>Easy go, easy come back?</Argument>"
s = s & "</ReturnArgument>"
s = s & "</soap:Body>"
s = s & "</soap:Envelope>"

mhttp.send s
MsgBox mhttp.responseText
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top