wsdl ファイルを使用して同期 SOAP メッセージを Web サーバーに送信しようとしています。IronPython の指示に従って、wsdl ファイルを IronPython にロードするための cs ファイルと dll を作成しました。SOAP メッセージ (Web サービスで必要) を作成しましたが、webRequest を適切に作成したとは思いません。
これが私のコードです:
import clr
clr.AddReference("System")
clr.AddReferenceToFileAndPath("C:\\Temp\MeetingSpaceService.dll")
clr.AddReference("System.Xml")
clr.AddReference("System.Web.Services")
from MeetingSpaceService import MeetingSpaceService
service = MeetingSpaceService()
from System.Net import WebClient
from System.IO import StreamWriter
from System.IO import StreamReader
from System.IO import StringWriter
import System.Xml
import System.Text
from System import Uri
from System.Xml import XmlTextWriter
from System.Xml import Formatting
from System.Web.Services import *
from System.Net import HttpWebRequest
import System.Object
import System.Array
import System.Byte
from System.Xml import XmlDocument
from System.IO import File
from System.Object import ToString
#from System.ServiceModel.Description import WsdlImporter as wsdl
from System.Web.Services.Description import (ServiceDescription, ServiceDescriptionImporter)
from System.Web.Services.Protocols import SoapHttpClientProtocol
from System.IO import MemoryStream
from System.Net import WebClient
readerboard = ''' <?xml version="1.0" encoding="utf-8"?>
</soap:Envelope> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header>
<wsa:Action>http://htng.org/PWSWG/2007/01/DigitalSignage#MeetingSpaceRequest</wsa:Action>
<wsa:MessageID>urn:uuid:44088898-6926-4537-b1a3-4acc8e9f71d0</wsa:MessageID>
<wsa:ReplyTo>
<wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>
</wsa:ReplyTo>
<wsa:To>http://localhost:2025/MeetingSpaceProviderService/Request.asmx</wsa:To>
<wsse:Security soap:mustUnderstand="1">
<wsu:Timestamp wsu:Id="Timestamp-e157d58f-6589-4b3e-b2a9-5510dd9f270f">
<wsu:Created>2011-04-17T15:35:25Z</wsu:Created>
<wsu:Expires>2012-07-17T15:40:25Z</wsu:Expires>
</wsu:Timestamp>"
<wsse:UsernameToken wsu:Id="SecurityToken-843aeb4f-07de-4c78-a438-e051d3baa764">
<wsse:Username>isacrb</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">is@cr6_662</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
" '''
uriString = "https://ice-services.starwoodhotels.com/readerboard"
uri = Uri(uriString)
try:
webRequest = HttpWebRequest.Create(uri)
webRequest.ContentType = "text/xml;charset=\"utf-8\""
webRequest.Accept = "text/xml"
webRequest.ContentLength = readerboard.Length
webRequest.Timeout = 1000000000
webRequest.Method = "POST"
webRequest.GetRequestStream()
webRequest.Write(readerboard)
webRequest.GetResponse()
except Exception, e:
print (9)
私はここで変更を加えましたが、今ここに私が得ているものがあります。Web サービスは同期的であるため、リクエストを送信すると、応答が自動的に返されると私は信じています。の時点で
rqt = webRequest.GetRequestStream() 次の行が読み取られるまでに約 1.5 ~ 2.5 秒の遅延があります。これは、メッセージが送信された後、通常は 1 秒程度の遅延があり、その後、返された XML データが応答ボックスに表示される SOAPUi の動作を模倣します。rqt= webRequest の後、応答を求めずに何らかの方法でストリームを読み取る必要があると考えています。WSDL をインポートするために作成した cs ファイルと dll を送って、あなたの意見を聞いてもよろしいですか。その時点で、サーバーにアクセスして、IDE で私が話していることを確認できるはずです。私はあなたの助けに感謝します。どうもありがとうございます。
上記の後に何が起こるかは次のとおりです。
>>> rqt = webRequest.GetRequestStream()
>>> rqt.Write(byte1,0,byte1.Length)
>>>
>>> #get the response here
>>> rsp = webRequest.GetResponse()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
SystemError: The remote server returned an error: (500) Internal Server Error.
>>> #create a stream reader to convert the raw response into UTF8 for text
>>> readStream = StreamReader(rsp.GetResponseStream(), System.Text.Encoding.UTF8
)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'rsp' is not defined
>>> #read the data from the stream into a string
>>> data = readStream.ReadToEnd()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'readStream' is not defined
>>> readStream.Close()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'readStream' is not defined
>>> rsp.Close()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'rsp' is not defined
>>> #Do stuff with the data here
>>> print data
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'data' is not defined
>>>