SAOP使用的一个例子
?
WebService?? URL:?? http://mes:8089/Service.asmx 名字空间:http://tempuri.org/ 调用方法:public string UpdateProduceLotTest(string[] TestInfo) TestInfo[0]:工作中心编号 TestInfo[1]:工位编号 TestInfo[2]:模具代号 TestInfo[3]:产品条码 TestInfo[4]:品质现象编号 TestInfo[5]:测试时间 调用返回一个字符串信息,调用成功返回Success或失败返回Fail。 ? ? 支持下列操作。有关正式定义,请查看服务说明。 ·???????? HelloWorld ·???????? UpdateProduceLotTest 此 Web 服务使用 http://tempuri.org/ 作为默认命名空间。建议: 公开 XML Web services 之前,请更改默认命名空间。每个 XML Web services 都需要一个唯一的命名空间,以便客户端应用程序能够将它与 Web 上的其他服务区分开。http://tempuri.org/ 可用于处于开发阶段的 XML Web services,而已发布的 XML Web services 应使用更为永久的命名空间。 应使用您控制的命名空间来标识 XML Web services。例如,可以使用公司的 Internet 域名作为命名空间的一部分。尽管有许多 XML Web services 命名空间看似 URL,但它们不必指向 Web 上的实际资源。(XML Web services 命名空间为 URI。) 使用 ASP.NET 创建 XML Web services 时,可以使用 WebService 特性的 Namespace 属性更改默认命名空间。WebService 特性适用于包含 XML Web services 方法的类。下面的代码实例将命名空间设置为“http://microsoft.com/webservices/”: C# [WebService(Namespace="http://microsoft.com/webservices/")] public class MyWebService { ??? // 实现 } Visual Basic <WebService(Namespace:="http://microsoft.com/webservices/")> Public Class MyWebService ??? ' 实现 End Class C++ [WebService(Namespace="http://microsoft.com/webservices/")] public ref class MyWebService { ??? // 实现 }; ? ? HelloWorld测试测试窗体只能用于来自本地计算机的请求。 SOAP 1.1以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。 POST /Service.asmx HTTP/1.1 Host: mes 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/" /> ? </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: mes 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/" /> ? </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> ? ? UpdateProduceLotTest测试测试窗体只能用于来自本地计算机的请求。 SOAP 1.1以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。 POST /Service.asmx HTTP/1.1 Host: mes Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://tempuri.org/UpdateProduceLotTest" ? <?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> ??? <UpdateProduceLotTest xmlns="http://tempuri.org/"> ????? <TestInfo> ??????? <string>string</string> ??????? <string>string</string> ????? </TestInfo> ??? </UpdateProduceLotTest> ? </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> ??? <UpdateProduceLotTestResponse xmlns="http://tempuri.org/"> ????? <UpdateProduceLotTestResult>string</UpdateProduceLotTestResult> ??? </UpdateProduceLotTestResponse> ? </soap:Body> </soap:Envelope> SOAP 1.2以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。 POST /Service.asmx HTTP/1.1 Host: mes 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> ??? <UpdateProduceLotTest xmlns="http://tempuri.org/"> ????? <TestInfo> ??????? <string>string</string> ??????? <string>string</string> ????? </TestInfo> ??? </UpdateProduceLotTest> ? </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> ??? <UpdateProduceLotTestResponse xmlns="http://tempuri.org/"> ????? <UpdateProduceLotTestResult>string</UpdateProduceLotTestResult> ??? </UpdateProduceLotTestResponse> ? </soap12:Body> </soap12:Envelope> ? Web_UpdateProduceLotTest.h文件内容如下: #import?? <msxml4.dll> class CallWebSerVice: public Singleton<CallWebSerVice> ? Web_UpdateProduceLotTest.cpp文件内容如下: #include "stdafx.h" ??? HRESULT?? hr; ??? try ??????? //指定Web服务的地址 ??????? SoapConnector->Property["EndPointURL"] = m_Web_Uri.GetString(); ??????? //与Web服务连接 ??????? //指定Web服务完成的操作 ??????? //?? 创建SoapSerializer对象 ??????? //?? 将serializer连接到connector的输入字符串 ??????? Serializer-> Init ( _variant_t ( ( IUnknown* ) SoapConnector->InputStream ) ); ??????? //?? 创建SOAP消息 ??????? Serializer-> StartElement ( "UpdateProduceLotTest",m_Web_NameSpace.GetString(),( _bstr_t ) "NONE",( _bstr_t ) "" ); ??????? Serializer-> EndBody(); ??????? //消息真正地发给Web服务 void CallWebSerVice::SetUrlInfor ( CString strUrl,CString strNamespace ) { ??? m_Web_Uri = strUrl; ??? m_Web_NameSpace = strNamespace; ??? m_Web_Action.Format ( TEXT ( "%s%s" ),strNamespace,CALL_WEB_SER_FUNCTION_NAME ); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |