我正在开发一个Access 2010的“工具”,希望能够将我们本地的Access数据库与在线数据库同步(在线数据库托管在我们无法控制或直接访问的服务器上)。我的背景不是VBA或VB.net,所以我对这种语言还比较陌生,因此任何帮助或建议都将不胜感激。到目前为止,以下是我编写的测试代码,以验证连接能力并更好地了解在获取有效响应时返回的内容。
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
我回来了:
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.
现在需要注意的是,我尝试过两种不同的方法来创建XML字符串。一种是创建以上所示的原始文本并将其发送到服务器,另一种是创建以上所示的字符串并使用loadXML
来创建该字符串。我不知道哪种方法更好,但两种方法都返回了相同的错误。
现在,我已经尝试了SOA Cleaner Express,并成功连接到了服务并获取了数据。既然SOA Cleaner能够连接,我认为使用SOA在VBA中发送的原始SOAP/XML字符串可能是一个很好的起点。我注意到,使用SOA Cleaner时它具有WsHttpBinding
作为WCF绑定,如果我将此绑定更改为BasicHttpBinding
,我会得到与在VBA中遇到的类似的错误消息,确切地说是:
Content Type text/xml; charset=utf-8 was not supported by service
我甚至不确定自己是否走在正确的方向上,但如果是的话,我该如何在VBA中设置或更改“绑定”?这里还有其他事情吗?我相信这很简单,但就像我说的,我没有VBA背景,WCF和SOAP对我来说也比较新。
我感激任何帮助。