+ -
当前位置:首页 → 问答吧 → asp实现web services 传递xml

asp实现web services 传递xml

时间:2010-08-20

来源:互联网

用asp实现与web services传递信息 web services相应的信息如下: 
RequestHandler
啟動服務流程(含電子案號)
測試
測試表單只適用於來自本機電腦的要求。 
SOAP 1.1
下列是 SOAP 1.1 要求與回應的範例。預留位置顯示之處必須代入實際的值。
POST /SEWebApplication/SImediator.asmx HTTP/1.1
Host: www.cp.gov.tw
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/RequestHandler"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
  <RequestHandler xmlns="http://tempuri.org/">
  <SID>string</SID>
  <InputData>string</InputData>
  <Token2>string</Token2>
  <TicketNo>string</TicketNo>
  </RequestHandler>
  </soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
  <RequestHandlerResponse xmlns="http://tempuri.org/">
  <RequestHandlerResult>string</RequestHandlerResult>
  </RequestHandlerResponse>
  </soap:Body>
</soap:Envelope>
也就是说 asp 要实现与该web services传递信息就要实现上面的资讯,所以代码如下:

  strBody='<?xml version="1.0" encoding="utf-8"?>';
  strBody=strBody+'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">&#39;;
 strBody=strBody+'<soap:Body>';
  strBody=strBody+'<RequestHandler xmlns="http://tempuri.org/">&#39;;
 strBody=strBody+'<SID>PUB0000554</SID>';
 strBody=strBody+'<InputData></InputData>';
 strBody=strBody+'<Token2></Token2>';
 strBody=strBody+'<TicketNo></TicketNo>';
 strBody=strBody+'</soap:Body>';
 strBody=strBody+'</soap:Envelope>'; 
xmlHttp.open("POST", "http://www.cp.gov.tw/SEWebApplication/SImediator.asmx", false); xmlHttp.setRequestHeader("HOST","www.cp.gov.tw");
 xmlHttp.setRequestHeader("Content-Type","text/xml; charset=utf-8"); xmlHttp.setRequestHeader("Content-Length",strBody.length);
 xmlHttp.setRequestHeader("SOAPAction","http://tempuri.org/RequestHandler");
 xmlHttp.send(strBody);

OK 到这边本来都好好的,SID、InputData、Token2、TicketNo这些节点填入相应的资料就可以的,但是问题来了,现在inpudata节点是要有另外一个xml,TicketNo是某个xml的一部分;所以不管我如何的把xml给填入到inpudata和TicketNo节点上,服务器的web services都回复是错的,所以在该出要怎么处理?如果是asp.net 应该就直接调用RequestHandler ( SID As string , InputData As string , Token2 As string , TicketNo As string ) As string 然后哦把xml当成字符串 传过去就可以了吧,但是asp 要怎么实现?大虾们 帮帮忙了

作者: wdyllff   发布时间: 2010-08-20

 

使用到的参数xml如下

1.使用RequestHandler
SIMediator.RequestHandler("AGM0000737", InputXml, Token2, TicketNo)

 

作者: wdyllff   发布时间: 2010-08-20

2.InputXml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CPSecuredPortalReq xmlns="http://www.gov.tw/CP/cpsp_definition">
<CP_UserInfo>
<Profile>
<Type>公務人員</Type>
<Name>蔡健民</Name>
<EngName></EngName>
<UID>A123456789</UID>
</Profile>
<ContactInfo>
<PostalAddress>桃園縣中壢市測試</PostalAddress>
<HomePhone>02-24236541:</HomePhone>
<TelephoneNumber>:</TelephoneNumber>
<Mobile></Mobile>
<Mail>[email protected]</Mail>
</ContactInfo>
</CP_UserInfo>
<CP_PublicServiceInfo>
<MessageInfo>
<TicketID>10000178_0951227_000022_7641</TicketID> 勿用重複每次都不一樣
</MessageInfo>
<ServiceInfo>
<ServiceID>PUB0000408</ServiceID>
<ServiceName>氣象資料查詢</ServiceName>
<ServiceAction>Forecast-1</ServiceAction>
</ServiceInfo>
<ServiceStatus>
<Status/>
<Description/>
</ServiceStatus>
</CP_PublicServiceInfo>
<CP_AP_ServiceReq>
<Header>
<ServiceInfo>
<ServiceID>AGM0000737</ServiceID>
<ServiceName>氣象資料查詢</ServiceName>
<ServiceAction>Forecast-1</ServiceAction>
</ServiceInfo>
<ServiceStatus>
<Status/>
<Description/>
</ServiceStatus>
</Header>
<Body>
<LIServiceReqMsg xmlns="http://www.gov.tw/CP/cps_definition" xmlns:cwb="http://www.cwb.gov.
tw/webservices/cwb_definition" xmlns:cm="http://www.gov.tw/CP/cm_definition">
<ServiceInfo>
<cm:BusinessElementaryServiceOID>AGM0000737</cm:BusinessElementaryServiceOID>
<cm:ServiceName>氣象局</cm:ServiceName>
<cm:TicketNo>10000178_0951227_000022_7641</cm:TicketNo>
<cm:ServiceStatus></cm:ServiceStatus>
<cm:ServiceStatusDescription></cm:ServiceStatusDescription>
<cm:CPTest></cm:CPTest>
</ServiceInfo>
<ServiceDetailInfo>
<cwb:ForecastQuery>
<cwb:query>台灣地區36小時</cwb:query>
<cwb:預報地區>所有</cwb:預報地區>
</cwb:ForecastQuery>
</ServiceDetailInfo>
</LIServiceReqMsg>
</Body>
</CP_AP_ServiceReq>
</CPSecuredPortalReq>

作者: wdyllff   发布时间: 2010-08-20

3.傳入Token2 (從此token2標籤開始)
<Token2><TokenInfo Id="CP_AA_TokenInfo"><ID>6621f0a4-036d-4c34-86c9-d2e93f8c41da</ID><SecureLevel>
1</SecureLevel><TimeStamp><issue_date>20061228112752</issue_date><expire_date>
20061228114752</expire_date></TimeStamp><HolderInfo><uid>A123354075</uid><account>
A123354075</account></HolderInfo><SrvInfo><SID>PUB0000408</SID><Roles /><Objects
/></SrvInfo></TokenInfo><Signature Id="Signature_1553" myxmlns="http://www.w3.org/
2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-
20010315" /><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /><Reference
URI="#CP_AA_TokenInfo"><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"
/><DigestValue>jseCcsgAh0Bdc++i2m3wr0+QXYg=</DigestValue></Reference></SignedInfo><SignatureValue>
D1hB14eb4zMwVynYH6kUfr84XBwcA3Z3Gf2hrFuz43yp+3Ny9kLRSqMznZRo/dDiJxaFjIvMekR8eIU3U83nBFPPh8i
a6mvQGWL45LKY5+J9c/UYHIW9lcq80fJCvIYTxXJCDNwLdDg79fbiKyshxsp49Lgz4IM1RPIV9lXTnu
k=</SignatureValue><KeyInfo><X509Data myxmlns="http://www.w3.org/2000/09/xmldsig#"><X509Certificate>

X509Certificate></X509Data></KeyInfo></Signature></Token2>
4.TicketNo=10000178_0951227_000022_7641

作者: wdyllff   发布时间: 2010-08-20