Reputation: 464
I am working on an Access 2010 'tool' that will hopefully allow me to sync our local Access database with an online one (hosted on a server that we have zero control over or direct access to). My background is not in VBA or VB.net so I am fairly new to this language so any help or suggestions would be appreciated. So far this is what I have written as a test to verify the ability to connect and to better understand what is returned when we do get a valid response.
Public Sub SendXML()
Dim myHTTP As MSXML2.ServerXMLHTTP60
Dim myDom As MSXML2.DOMDocument
Dim myXML As String
Set myHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")
Set myDom = CreateObject("MSXML2.DOMDocument")
myDom.async = False
myXML = "<s:Envelope xmlns:a=" & Chr(34) & "http://www.w3.org/2005/08/addressing" & Chr(34) & "xmlns:s=" & Chr(34) & "http://www.w3.org/2003/05/soap-envelope" & Chr(34) & "><s:Header><a:Action s:mustUnderstand=" & Chr(34) & "1" & Chr(34) & ">http://tempuri.org/IWcfService/Get_InitiativeList_CSV</a:Action></s:Header><s:Body><Get_InitiativeList_CSV xmlns=" & Chr(34) & "http://tempuri.org/" & Chr(34) & "><userID>MYUSERID</userID></Get_InitiativeList_CSV></s:Body></s:Envelope>"
myDom.LoadXML (myXML)
myHTTP.Open "post", "https://server/WcfService/WcfService.svc", False
myHTTP.setRequestHeader "Content-Type", "application/xml"
'myHTTP.send (myDom.XML)
myHTTP.send (myXML)
MsgBox myHTTP.responseText
End Sub
I get back:
The server cannot service the request because the media type is unsupported.
A couple things to note above. I tried two different way to create the XML string. One creating it as you see above and sending that raw text to the server. And creating the string as you see above and using loadXML
to create the string. I do not know why one would be better than the other but both returned the same error.
Now, I have tried SOA Cleaner Express and am able to connect successfully to the service and get data back. Since SOA Cleaner is able to connect I figured using the RAW SOAP/XML string SOA sends in VBA might be a good starting point. I noticed that using SOA cleaner it has a WCF Binding as WsHttpBinding
and if I change this binding to BasicHttpBinding
I get a similar error message as I am getting in VBA, to be exact:
Content Type text/xml; charset=utf-8 was not supported by service
Not even sure I am going in the right direction, but if I am, how do I set or change the 'binding' in VBA? Is there something else going on here? I am sure it is something simple, but like I said I do not have a VBA background, and WCF and SOAP are somewhat new to me as well.
I appreciate any assistance.
Upvotes: 3
Views: 3576
Reputation: 14088
This may be far-fetched, but given that the second error is more descriptive than the first error, have you tried specifying the charset?
myHTTP.setRequestHeader "Content-Type", "application/xml; charset=utf-8"
Upvotes: 0
Reputation: 1908
For starters, the binding from the client must match the service, so if the service only supports wsHttpBinding
, the client must use that as well.
For added flexiblity calling a WCF service from VBA, including the ability to specify the binding, you may want to use monikers instead. Here is an example of service monkier being constructed and used in VBA:
Dim addr As String
addr = "service:mexAddress=""net.tcp://localhost:7891/Test/WcfService1/Service1/Mex"","
addr = addr + "address=""net.tcp://localhost:7891/Test/WcfService1/Service1/"","
addr = addr + "contract=""IService1"", contractNamespace=""http://tempuri.org/"","
addr = addr + "binding=""NetTcpBinding_IService1"", bindingNamespace=""http://tempuri.org/"""
Dim service1 As Object
Set service1 = GetObject(addr)
MsgBox service1.GetData(12)
Here are some links with more info, including the source of this code snippet:
http://msdn.microsoft.com/en-us/library/ms752245(v=vs.110).aspx http://damianblog.com/2009/07/05/excel-wcf/
Upvotes: 1