سؤال

هناك خدمة WCF مع التكوين:

<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 Service: تهيئة منفذ الخدمة للخدمة فشل MyService HRESULT = 0x80004005 - WSDLPort: فشل تحليل المعلومات الملزمة ل PORT BASSICHTTPBinding_imyService HRESULT = 0x80004005 - WSDLPort: تعذر تهيئة عملية تشغيل Port BasichttpBinding_imyService HRESULT = 0x8000 4005 - WSDLoperation: التشغيل // def: porttype [@ الاسم = "IMYSERVICE"] / def: العملية [@ name = "mymethod"] لم يكن وجدت في قسم porttype hresult = 0x80004005

ما الذي يحدث خطأ؟ من فضلك، مساعدة.

يحرر:

شكرا لك، تشيزو، للإجابة. يبدو أن المشكلة في MSSOAP هي أنها تتطلب إدراج جميع مخططات XSD مضمنة في ملف WSDL الذي تم إنشاؤه. WCF لا يفعل ذلك بشكل افتراضي.

هل كانت مفيدة؟

المحلول

لا تستخدم MSSOAP. أعتقد أنه من الدعم الآن، خلال 3 أو 4 سنوات الماضية. فكر في استخدام XMLHTTP، وهو جزء من MSXML، وهو مدعوم ويستمر في الاحتفاظ به. سيكون لديك لبناء مغلف الصابون يدويا. لكنه أكثر موثوقية بهذه الطريقة.

مثال رمز

' 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-le-use لمعرفة كيفية تحديد إصدار من MSXML.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top