通过VBScript调用WCF服务

有一个WCF服务的configuration:

<services> <service name="MyService" behaviorConfiguration="MyServiceBehavior"> <endpoint binding="basicHttpBinding" contract="IMyService" /> <host> <baseAddresses> <add baseAddress="http://localhost:8001/MyService" /> </baseAddresses> </host> </service> </services> <behaviors> <serviceBehaviors> <behavior name="MyServiceBehavior"> <serviceMetadata httpGetEnabled="True" /> </behavior> </serviceBehaviors> </behaviors> 

这个脚本应该叫它:

 Option Explicit Dim soapClient Dim serviceUri Dim serviceName Dim portName Dim result serviceUri = "http://localhost:8001/MyService" serviceName = "MyService" portName = "BasicHttpBinding_IMyService" Set soapClient = CreateObject("MSSOAP.soapClient") soapClient.ClientProperty("ServerHTTPRequest") = True soapClient.mssoapinit serviceUri & "?WSDL", serviceName, portName 

运行脚本时出现此错误:

客户端:WSDLReader:分析WSDL文件失败HRESULT = 0x8 0004005 – WSDLReader:服务初始化失败HRESULT = 0x80004005 – WSDL服务:服务端口的初始化MyService失败HRESULT = 0x80004005 – WSDLPort:分析端口的绑定信息BasicHttpBinding_IMyService失败HRESULT = 0x80004005 – WSDLPort:无法初始化端口BasicHttpBinding_IMyService的操作HRESULT = 0x8000 4005 – WSDLOperation:操作// def:portType [@ name =“IMyService”] / def:operation [@ name =“MyMethod”] was not在porttype部分findHRESULT = 0x80004005

出了什么问题? 请帮忙。

编辑:

谢谢你,谢谢你的回答。 MSSOAP的问题似乎是要求将所有的xsd模式内联包含在生成的WSDL文件中。 WCF默认不会这样做。

One Solution collect form web for “通过VBScript调用WCF服务”

不要使用MSSOAP。 我认为现在已经过去三四年了。 考虑使用MSXML的一部分XmlHttp,并支持并继续保持。 你将不得不手动构build一个SOAP信封。 但是这样更可靠。

示例代码

 ' URL to the WCF service' url= "http://server:port/Wcf.Service.Address" Dim requestDoc Set requestDoc = WScript.CreateObject("MSXML2.DOMDocument.6.0") Dim root Set root = requestDoc.createNode(1, "Envelope", "http://schemas.xmlsoap.org/soap/envelope/") requestDoc.appendChild root Dim nodeBody Set nodeBody = requestDoc.createNode(1, "Body", "http://schemas.xmlsoap.org/soap/envelope/") root.appendChild nodeBody Dim nodeOp Set nodeOp = requestDoc.createNode(1, "Register", "urn:Your.Namespace.Here") nodeBody.appendChild nodeOp Dim nodeRequest Set nodeRequest = requestDoc.createNode(1, "request", "urn:Your.Namespace.Here") 'content of the request will vary depending on the WCF Service.' ' This one takes just a plain string. ' nodeRequest.text = "Hello from a VBScript client." nodeOp.appendChild nodeRequest Set nodeRequest = Nothing Set nodeOp = Nothing Set nodeBody = Nothing Set root = Nothing 'the request will look like this:' ' <s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'> ' ' <s:Body> ' ' <Register xmlns='urn:Your.Namespace.Here'> ' ' <request>hello from a VBScript client.</request> ' ' </Register> ' ' </s:Body> ' ' </s:Envelope>' WSCript.Echo "sending request " & vbcrlf & requestDoc.xml dim xmlhttp set xmlhttp = WScript.CreateObject("MSXML2.ServerXMLHTTP.6.0") ' set the proxy as necessary and desired ' xmlhttp.setProxy 2, "http://localhost:8888" xmlhttp.Open "POST", url, False xmlhttp.setRequestHeader "Content-Type", "text/xml" ' set SOAPAction as appropriate for the operation ' xmlhttp.setRequestHeader "SOAPAction", "urn:Set.As.Appropriate" xmlhttp.send requestDoc.xml WScript.Echo vbcrlf & "Raw XML response:" & vbcrlf WSCript.Echo xmlhttp.responseXML.xml dim response set response= xmlhttp.responseXML 'the response is an MSXML2.DOMDocument.6.0' 'party on the response here - XPath, walk the DOM, etc. ' 

仅供参考:请参阅msxml- how -version-of-i-use来了解如何selectMSXML版本。

  • 在iPhone上使用Objective-C来使用WCF Web服务
  • 这个WCF错误是什么意思:“自定义工具警告:无法导入wsdl:portType”
  • https与WCF错误:“无法find匹配scheme https的基地址”
  • 什么是WCF客户端`使用`块问题的最佳解决方法?
  • 有时添加WCF服务引用会生成一个空的reference.cs
  • IIS WCF服务托pipe与Windows服务
  • WCF服务返回“方法不允许”
  • 为什么开发人员应该使用Web服务而不是直接连接到数据库?
  • 使用ConfigurationManager加载System.ServiceModelconfiguration部分
  • 如何使用Fiddler来监视WCF服务
  • 你在你的WCF Web服务中使用枚举types吗?