用nusoap调用C#作的webservice,该webservice的一个方法要求输入数据类型为datetime,请问php+nusoap该怎么做?以字符串形式调用返回错误,不要说修改webservice。
ERROR: soap:Client: System.Web.Services.Protocols.SoapException: 服务器无法读取请求。 ---> System.InvalidOperationException: XML 文档(1, 394)中有错误。 ---> System.FormatException: 字符串“2009-11-11 12:12:12”不是有效的 AllXsd 值。 在 System.Xml.Schema.XsdDateTime..ctor(String text, XsdDateTimeFlags kinds) 在 System.Xml.XmlConvert.ToDateTime(String s, XmlDateTimeSerializationMode dateTimeOption) 在 System.Xml.Serialization.XmlCustomFormatter.ToDateTime(String value) 在 System.Xml.Serialization.XmlSerializationReader.ToDateTime(String value) 在 Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read1_HelloWorld() 在 Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer.Deserialize(XmlSerializationReader reader) 在 System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) --- 内部异常堆栈跟踪的结尾 --- 在 System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) 在 System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle) 在 System.Web.Services.Protocols.SoapServerProtocol.ReadParameters() --- 内部异常堆栈跟踪的结尾 --- 在 System.Web.Services.Protocols.SoapServerProtocol.ReadParameters() 在 System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
ERROR: soap:Client: System.Web.Services.Protocols.SoapException: 服务器无法读取请求。 ---> System.InvalidOperationException: XML 文档(1, 394)中有错误。 ---> System.FormatException: 字符串“2009-11-11 12:12:12”不是有效的 AllXsd 值。 在 System.Xml.Schema.XsdDateTime..ctor(String text, XsdDateTimeFlags kinds) 在 System.Xml.XmlConvert.ToDateTime(String s, XmlDateTimeSerializationMode dateTimeOption) 在 System.Xml.Serialization.XmlCustomFormatter.ToDateTime(String value) 在 System.Xml.Serialization.XmlSerializationReader.ToDateTime(String value) 在 Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read1_HelloWorld() 在 Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer.Deserialize(XmlSerializationReader reader) 在 System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) --- 内部异常堆栈跟踪的结尾 --- 在 System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) 在 System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle) 在 System.Web.Services.Protocols.SoapServerProtocol.ReadParameters() --- 内部异常堆栈跟踪的结尾 --- 在 System.Web.Services.Protocols.SoapServerProtocol.ReadParameters() 在 System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
必须严格按照格式发送参数,c#那边认为的datetime格式,并不一定和你主观认为的datetime格式吻合。
- <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
- <wsdl:types>
- <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
- <s:element name="HelloWorld">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="dt" type="s:dateTime" />
</s:sequence>
</s:complexType>
</s:element>
- <s:element name="HelloWorldResponse">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
- <wsdl:message name="HelloWorldSoapIn">
<wsdl:part name="parameters" element="tns:HelloWorld" />
</wsdl:message>
- <wsdl:message name="HelloWorldSoapOut">
<wsdl:part name="parameters" element="tns:HelloWorldResponse" />
</wsdl:message>
- <wsdl:portType name="ServiceSoap">
- <wsdl:operation name="HelloWorld">
<wsdl:input message="tns:HelloWorldSoapIn" />
<wsdl:output message="tns:HelloWorldSoapOut" />
</wsdl:operation>
</wsdl:portType>
- <wsdl:binding name="ServiceSoap" type="tns:ServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="HelloWorld">
<soap:operation soapAction="http://tempuri.org/HelloWorld" style="document" />
- <wsdl:input>
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:binding name="ServiceSoap12" type="tns:ServiceSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="HelloWorld">
<soap12:operation soapAction="http://tempuri.org/HelloWorld" style="document" />
- <wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:service name="Service">
- <wsdl:port name="ServiceSoap" binding="tns:ServiceSoap">
<soap:address location="http://localhost:89/Service.asmx" />
</wsdl:port>
- <wsdl:port name="ServiceSoap12" binding="tns:ServiceSoap12">
<soap12:address location="http://localhost:89/Service.asmx" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。POST /Service.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/HelloWorld"<?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>
<HelloWorld xmlns="http://tempuri.org/">
<dt>dateTime</dt>
</HelloWorld>
</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>
<HelloWorldResponse xmlns="http://tempuri.org/">
<HelloWorldResult>string</HelloWorldResult>
</HelloWorldResponse>
</soap:Body>
</soap:Envelope>
SOAP 1.2
以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。POST /Service.asmx HTTP/1.1
Host: localhost
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<HelloWorld xmlns="http://tempuri.org/">
<dt>dateTime</dt>
</HelloWorld>
</soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<HelloWorldResponse xmlns="http://tempuri.org/">
<HelloWorldResult>string</HelloWorldResult>
</HelloWorldResponse>
</soap12:Body>
</soap12:Envelope>
HTTP POST
以下是 HTTP POST 请求和响应示例。所显示的占位符需替换为实际值。POST /Service.asmx/HelloWorld HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: lengthdt=string
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">string</string>
webservice源码就是这样:
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service () { //如果使用设计的组件,请取消注释以下行
//InitializeComponent();
} [WebMethod]
public string HelloWorld(DateTime dt) {
return dt.ToString();
}
}
=======================================
有啊,不是发了个链接给你么
http://www.w3.org/TR/xmlschema-2/#dateTimeserver端提供了个方法HelloWorld给你调用,用php封装好的类,soapclient既可调用,当然也可用fsockopen模拟soap,其实就是报头用http,报文用soap xml,和你发的那个一样。//参考。
$soapclient = new SoapClient("http://localhost:89/Service.asmx");
echo $soapclient->HelloWorld("2009-11-11T12:12:12");//貌似date与time中间加个T既可
$soapclient = new SoapClient("wsdl文件地址");/
echo $soapclient->HelloWorld("2009-11-11T12:12:12");//貌似date与time中间加个T既可