我最近一直在努力通过WSDL Web服务发送数据,这似乎是由C#编写的,并在WINDOWS上运行。
https://occurrences.caa.govt.nz/Test/CAA.Part12Interface.CaptureService.CaptureService.svc
Firts off ...我必须将WINS URL解析为IP地址...因为它在这个问题中并不重要,所以我跳过了解决方法。所以只需将caa-ws-01替换为occurrence事件.caa.govt.nz
下面是WSDL本身和定义complexTypes的XSD
WSDL
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions targetNamespace="http://www.caa.govt.nz/CAA.Part12Interface.CaptureService" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:tns="http://www.caa.govt.nz/CAA.Part12Interface.CaptureService" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<wsdl:types>
<xsd:schema targetNamespace="http://www.caa.govt.nz/CAA.Part12Interface.CaptureService/Imports">
<xsd:import schemaLocation="https://caa-ws-01/Test/CAA.Part12Interface.CaptureService.CaptureService.svc?xsd=xsd0" namespace="http://www.caa.govt.nz/CAA.Part12Interface.CaptureService"/>
<xsd:import schemaLocation="https://caa-ws-01/Test/CAA.Part12Interface.CaptureService.CaptureService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="ICaptureService_SubmitData_InputMessage">
<wsdl:part name="parameters" element="tns:SubmitData"/>
</wsdl:message>
<wsdl:message name="ICaptureService_SubmitData_OutputMessage">
<wsdl:part name="parameters" element="tns:SubmitDataResponse"/>
</wsdl:message>
<wsdl:message name="ICaptureService_SubmitData_CaptureServiceFaultFault_FaultMessage">
<wsdl:part name="detail" element="tns:CaptureServiceFault"/>
</wsdl:message>
<wsdl:message name="ICaptureService_SubmitMobileData_InputMessage">
<wsdl:part name="parameters" element="tns:SubmitMobileData"/>
</wsdl:message>
<wsdl:message name="ICaptureService_SubmitMobileData_OutputMessage">
<wsdl:part name="parameters" element="tns:SubmitMobileDataResponse"/>
</wsdl:message>
<wsdl:message name="ICaptureService_SubmitMobileData_CaptureServiceFaultFault_FaultMessage">
<wsdl:part name="detail" element="tns:CaptureServiceFault"/>
</wsdl:message>
<wsdl:portType name="ICaptureService">
<wsdl:operation name="SubmitData">
<wsdl:input wsaw:Action="http://www.caa.govt.nz/CAA.Part12Interface.CaptureService/ICaptureService/SubmitData" message="tns:ICaptureService_SubmitData_InputMessage"/>
<wsdl:output wsaw:Action="http://www.caa.govt.nz/CAA.Part12Interface.CaptureService/ICaptureService/SubmitDataResponse" message="tns:ICaptureService_SubmitData_OutputMessage"/>
<wsdl:fault wsaw:Action="http://www.caa.govt.nz/CAA.Part12Interface.CaptureService/ICaptureService/SubmitDataCaptureServiceFaultFault" name="CaptureServiceFaultFault" message="tns:ICaptureService_SubmitData_CaptureServiceFaultFault_FaultMessage"/>
</wsdl:operation>
<wsdl:operation name="SubmitMobileData">
<wsdl:input wsaw:Action="http://www.caa.govt.nz/CAA.Part12Interface.CaptureService/ICaptureService/SubmitMobileData" message="tns:ICaptureService_SubmitMobileData_InputMessage"/>
<wsdl:output wsaw:Action="http://www.caa.govt.nz/CAA.Part12Interface.CaptureService/ICaptureService/SubmitMobileDataResponse" message="tns:ICaptureService_SubmitMobileData_OutputMessage"/>
<wsdl:fault wsaw:Action="http://www.caa.govt.nz/CAA.Part12Interface.CaptureService/ICaptureService/SubmitMobileDataCaptureServiceFaultFault" name="CaptureServiceFaultFault" message="tns:ICaptureService_SubmitMobileData_CaptureServiceFaultFault_FaultMessage"/>
</wsdl:operation>
</wsdl:portType>
</wsdl:definitions>
XSD:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" targetNamespace="http://www.caa.govt.nz/CAA.Part12Interface.CaptureService" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.caa.govt.nz/CAA.Part12Interface.CaptureService">
<xs:element name="SubmitData">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="data" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="SubmitDataResponse">
<xs:complexType>
<xs:sequence/>
</xs:complexType>
</xs:element>
<xs:complexType name="CaptureServiceFault">
<xs:sequence>
<xs:element minOccurs="0" name="DeveloperMessage" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="UserMessage" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="CaptureServiceFault" nillable="true" type="tns:CaptureServiceFault"/>
<xs:element name="SubmitMobileData">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="data" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="SubmitMobileDataResponse">
<xs:complexType>
<xs:sequence/>
</xs:complexType>
</xs:element>
</xs:schema>
我在Ubuntu服务器上使用PHP SoapClient来测试Web服务,我能够__getFunctions()和__getTypes(),但是,当我尝试调用其中一个函数:SubmitData时,它返回我:< / p>
object(SoapFault)#5 (9) {
["message":protected]=>
string(21) "Internal Server Error"
["string":"Exception":private]=>
string(0) ""
["code":protected]=>
int(0)
["file":protected]=>
string(36) "[PATH_TO_FOLDER]/index.php"
["line":protected]=>
int(36)
["trace":"Exception":private]=>
array(3) {
[0]=>
array(4) {
["function"]=>
string(11) "__doRequest"
["class"]=>
string(10) "SoapClient"
["type"]=>
string(2) "->"
["args"]=>
array(5) {
[0]=>
string(12609) "<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://www.caa.govt.nz/CAA.Part12Interface.CaptureService"><env:Body><ns1:data><?xml version="1.0" encoding="utf-8"?>
<ClientOccurrence
xsi:schemaLocation="http://caa.govt.nz/Schema/Occurrence_1_0 ../Schema/Occurrence_1_0.xsd"
xmlns="http://caa.govt.nz/Schema/Occurrence_1_0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
//...
</ClientOccurrence>
</ns1:data>"
}
}
}
}
[2]=>
array(6) {
["file"]=>
string(36) "[PATH_TO_FOLDER]/index.php"
["line"]=>
int(36)
["function"]=>
string(10) "SubmitData"
["class"]=>
string(10) "SoapClient"
["type"]=>
string(2) "->"
["args"]=>
array(1) {
[0]=>
object(SoapVar)#4 (2) {
["enc_type"]=>
int(147)
["enc_value"]=>
string(12397) "<ns1:data><?xml version="1.0" encoding="utf-8"?>
<ClientOccurrence
xsi:schemaLocation="http://caa.govt.nz/Schema/Occurrence_1_0 ../Schema/Occurrence_1_0.xsd"
xmlns="http://caa.govt.nz/Schema/Occurrence_1_0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
//...
</ClientOccurrence>
</ns1:data>"
}
}
}
}
["previous":"Exception":private]=>
NULL
["faultstring"]=>
string(21) "Internal Server Error"
["faultcode"]=>
string(4) "HTTP"
}
以下是我的代码:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
try {
$client = new SoapClient('https://occurrences.caa.govt.nz/Test/CAA.Part12Interface.CaptureService.CaptureService.svc?wsdl',array('soap_version'=>SOAP_1_2,'exceptions'=>FALSE,'trace'=>1,'cache_wsdl' => WSDL_CACHE_NONE));
$fn = '../occurences/5/182/1437104659.xml';
$fh = fopen($fn,'r');
if (FALSE === $fh) {
exit("Failed to open stream to URL");
}
$contents = fread($fh,filesize($fn));
$SubmitData = new stdClass();
//$SubmitData->data = $contents; //the parameter this function takes is a XML string. But, using this line, will convert the '<' and '>' in $contents into < and >, so I use the line below instead
$SubmitData->data = new SoapVar('<ns1:data>'.$contents.'</ns1:data>', XSD_ANYXML);
$response = $client->SubmitData($SubmitData);
print '<pre>';
if (is_soap_fault($response)) {
var_dump($response);
}else{
}
}catch(Exception $e) {
var_dump($response);
}
?>
我搜索了互联网,它说如果服务器返回内部服务器错误,则表示服务器不喜欢我提交的参数。我现在很困惑,不知道我做错了什么。
我转向询问客户端的IT支持,但没有多大帮助,但只给了我一个.exe文件(带有.config和.dll),只适用于Windows平台,.NET Framework环境。他们声称这个exe“使用相同的XML数据调用完全相同的函数”,然后向我展示了C#中的示例代码:
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
var target = new CaptureServiceClient();
target.Open();
const string data = [SOME_XML_STRING];
target.SubmitMobileData(data);
target.Close();
}
}
所以,为了诊断它可能出错的地方,我做了:
我尝试了一个不同的Web服务(http://www.webservicex.com/globalweather.asmx?wsdl),代码类似,并且它有效(虽然我没有传递XML字符串作为参数) - 代码工作,我们的服务器SOAP模块正在运行确定
因为客户端还为我们提供了一个'.exe'文件,用于在Windows平台上进行测试,所以我尝试使用相同的XML数据,并且它有效。 - 所以我假设数据很好,他们的WSDL服务运行正常吗?虽然在示例代码中,他们将参数作为一种字符串抛出(而在PHP soapclient中我必须将它包装在一个对象中..)
我试着调用__getLastRequest(),它返回SOAP信封及其内容,所以我假设SOAP服务器确实收到了我的请求。
现在我没有想法 - 我是SOAP新手,之前还没有完成PHP soapclient和.NET webservice。在这个领域有经验的人可以伸出援手吗?