views:

2522

answers:

4

DOING THE POST IS NOT THE PROBLEM! Formatting the message so that I get a response is the problem.

Ideally I'd be able to construct a message and use WinHTTP to perform a post to a WCF service (hosted in IIS) and get a response, but so far I've been unable to construct something that works properly.

Does anyone have an example of doing this that is straightforward?

In the 2.0 Web Service world this was as easy as putting a setting in the web.config to get the service to respond to a post and then calling the appropriate web method with the right parameters. There seems to be no analogue for this in the WCF world.

As of now there is no option for me to convert the consumer (the vbscript end) into .NET.

Assume at this point that at the endpoint I can convert to using whatever bindings are available right up to whatever is supported in .NET 3.5, but at the same time if this can be done using WsHttpBinding or BasicHttpBinding then the proper answer to this would be to describe how to format the message for either of those bindings in the context of VBScript or if there is no way to do that then just say, you can't do it. If this can be done using WebHTTPBinding then I have not found a way to make it happen as I've already investigated the WebInvoke attribute and been unable to create a test from VBScript to WCF that worked properly.

Assume that the posted data type is a string and the response is also a string.

Also this question is not WinHTTP related. I already know how to perform the post using WinHTTP it's the construction of the message that the WCF service will respond to that is the problem.

While I could use something other than WinHTTP to perform the post from ASP over to the WCF service such as XMLHTTP I still have the problem of constructing an XML message that the WCF service will respond to. I've tried variations on this and still am unable to fathom what sort of format I need to use to make this happen.

I know theoretically that all the WCF service needs is a properly formatted message. I'm just unable to construct the message properly and usually while everyone has some suggestion on how to send the message I have yet to see someone give an actual example of what the proper message format would be in this situation since everyone is so used to using .NET to send the message and it's all done for you in that context.

A: 

I wote some code a while ago for an excel macro which reads a XML file, posts the contents to a URL then saves the result.

Sub ExportToHTTPPOST()
Dim sURL, sExtraParams
Const ForReading = 1, ForWriting = 2, ForAppending = 3

Set rs = CreateObject("Scripting.FileSystemObject")
Set r = rs.OpenTextFile("y:\test.xml", ForReading)

Set Ws = CreateObject("Scripting.FileSystemObject")
Set w = Ws.OpenTextFile("Y:\test2.xml", ForWriting, True)

Do Until r.AtEndOfStream

    sData = sData & r.readline

Loop

sURL = "http://MyServer/MyWebApp.asp"

sData = "payload=" & sData

    Set objHTTP = New WinHttp.WinHttpRequest

            objHTTP.Open "POST", sURL, False
            objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
            objHTTP.send sData
            w.writeline objHTTP.ResponseText
    Set objHTTP = Nothing
    w.Close
    r.Close
End Sub
Spike
+1  A: 

You don't specify one thing: What binding are you exposing your service as? If you're using WsHttpBinding or BasicHttpBinding, then there's no simple "http post" you can do, because you need to include at the very least the entire SOAP envelope (with the right SOAP version and potentially security headers and so forth).

If you're using (or can migrate to) .NET 3.5, then there's a new binding explicitly created to support scenarios like this, where you want your service to be exposed not as a SOAP service but as fully REST-like service, or simply as XML/JSON over HTTP. It's called the WebHttpBinding.

There are many options you can tweak, but it's very likely you might just be able to add a new endpoint with webHttpBinding and have that working almost right away.

This might give you a head-start on the new programming model: http://msdn.microsoft.com/en-us/library/bb412169.aspx

tomasr
A: 

This is the simplest code I've got for doing a background HTTP post in ASP

Set objXML = CreateObject("MSXML2.ServerXMLHTTP.6.0")
objXML.open "POST", url, false
objXML.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objXML.send("key="& Server.URLEncode(xmlvalue))
Set responseXML = objXML.responseXML
Set objXML = nothing

This just requires that you have the MSXML objects installed on your server. I use this for all kinds of things including an XML-RPC server/client in ASP.

edit: Re-read your question and if you are set on that specific way then this won't help, but if you are really just looking for a way to access your webservice this would work as long as you construct your XML to post correctly.

Skyhigh
A: 

What http verb is uesed here ?

Set objXML = CreateObject("MSXML2.ServerXMLHTTP.6.0") objXML.open "POST", url, false

Is this a http soap or http post what is t

Can you please clear

gray
@gray: thanks for trying to help. You may have noticed this question is almost 2 years old.
John Saunders