加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

SAOP使用的一个例子

发布时间:2020-12-17 01:11:13 所属栏目:安全 来源:网络整理
导读:? WebService?? URL:?? http://mes:8089/Service.asmx 名字空间:http://tempuri.org/ 调用方法:public string UpdateProduceLotTest(string[] TestInfo) TestInfo[0]:工作中心编号 TestInfo[1]:工位编号 TestInfo[2]:模具代号 TestInfo[3]:产品条码 TestIn
?

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>
#include "Singleton.h"
//using?? namespace?? MSXML2;
#import?? "C:Program FilesCommon FilesMSSoapBinariesMSSOAP30.dll"? exclude( "IStream ",?? "ISequentialStream ",?? "_LARGE_INTEGER ","_ULARGE_INTEGER ",?? "tagSTATSTG ",?? "_FILETIME ")
using?? namespace? MSSOAPLib30;
/*#define Web_Uri "http://mes:8089/Service.asmx"
#define Web_NameSpace "http://tempuri.org/"
#define Web_Action "http://tempuri.org/UpdateProduceLotTest"
*/

class CallWebSerVice: public Singleton<CallWebSerVice>
{
public:
??? CString?? BeginSoap ( CString *TestInfo );
??? void SetUrlInfor ( CString strUrl,CString strNamespace );
private:
??? CString m_Web_Uri;
??? CString m_Web_NameSpace;
??? CString m_Web_Action;
};

?

Web_UpdateProduceLotTest.cpp文件内容如下:

#include "stdafx.h"
#include "Web_UpdateProduceLotTest.h"
#include "CommonDef.h"
CString CallWebSerVice::BeginSoap ( CString *TestInfo )
{
??? ISoapConnectorPtr?? SoapConnector;
??? ISoapSerializerPtr?? Serializer;
??? ISoapReaderPtr?? Reader;

??? HRESULT?? hr;

??? try
??? {
??????? hr = CoInitialize ( NULL ); //初始化com环境
??????? if ( FAILED ( hr ) )
??????? {
??????????? MessageBox ( NULL,TEXT ( "faile" ),TEXT ( "error" ),0 );
??????????? return L"";
??????? }
??????? //创建SoapConnector类的对象
??????? SoapConnector.CreateInstance ( __uuidof ( HttpConnector30 ) );

??????? //指定Web服务的地址

??????? SoapConnector->Property["EndPointURL"] = m_Web_Uri.GetString();
??????? SoapConnector->Property["Timeout"] = _variant_t ( ( long ) 4000 );

??????? //与Web服务连接
??????? hr = SoapConnector-> Connect();
??????? if ( FAILED ( hr ) )
??????????? return?? L"SoapConnector::Connect失败 ";

??????? //指定Web服务完成的操作
??????? SoapConnector-> Property?? ["SoapAction"]?? =?? m_Web_Action.GetString();
??????? //准备发送消息给Web服务
??????? SoapConnector-> BeginMessage();

??????? //?? 创建SoapSerializer对象
??????? Serializer.CreateInstance ( __uuidof ( SoapSerializer30 ) );

??????? //?? 将serializer连接到connector的输入字符串

??????? Serializer-> Init ( _variant_t ( ( IUnknown* ) SoapConnector->InputStream ) );

??????? //?? 创建SOAP消息
??????? Serializer-> StartEnvelope ( "","","" );
??????? Serializer-> StartBody ( "" );

??????? Serializer-> StartElement ( "UpdateProduceLotTest",m_Web_NameSpace.GetString(),( _bstr_t ) "NONE",( _bstr_t ) "" );
??????? Serializer->StartElement ( "TestInfo","NONE","" );
??????? for ( int i = 0 ; i < 6 ; i++ )
??????? {
??????????? Serializer->StartElement ( "string","" );
??????????? Serializer-> WriteString ( SysAllocString ( TestInfo[i] ) );
??????????? Serializer->EndElement();
??????? }
??????? Serializer->EndElement();///////////////TestInfo
??????? Serializer-> EndElement(); //////////////UpdateProduceLotTest

??????? Serializer-> EndBody();
??????? Serializer->EndEnvelope();

??????? //消息真正地发给Web服务
??????? hr = SoapConnector->EndMessage();
??????? if ( FAILED ( hr ) )
??????????? return?? L" ";
??????? //?? 读取响应
??????? Reader.CreateInstance ( __uuidof ( SoapReader30 ) );
??????? //?? 将reader联接到connector的输出字符串
??????? Reader->Load ( _variant_t ( ( IUnknown* ) SoapConnector->OutputStream ),_T ( "" ) );
??????? CString str = Reader->RpcResult->Gettext();
??????? return?? str;
??? }
??? catch ( _com_error e )
??? {
??????? CString msg = TEXT ( "WebService调用出错,请检查URL与名字空间是否正确,错误描述:" );
??????? msg += e.ErrorMessage();
??????? return? msg;
??? }
}

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 ); }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读