Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sunxiaotianmg
Mozi.HttpEmbedded
提交
fdafabf3
M
Mozi.HttpEmbedded
项目概览
sunxiaotianmg
/
Mozi.HttpEmbedded
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
Mozi.HttpEmbedded
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
fdafabf3
编写于
6月 24, 2021
作者:
JasonWcx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
实现SOAP文档生成
上级
006f512b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
152 addition
and
16 deletion
+152
-16
Mozi.HttpEmbedded/Page/RuntimeApi.cs
Mozi.HttpEmbedded/Page/RuntimeApi.cs
+13
-0
Mozi.HttpEmbedded/WebService/SOAP.cs
Mozi.HttpEmbedded/WebService/SOAP.cs
+139
-16
未找到文件。
Mozi.HttpEmbedded/Page/RuntimeApi.cs
浏览文件 @
fdafabf3
...
...
@@ -260,6 +260,19 @@ namespace Mozi.HttpEmbedded.Page
rm
.
success
=
true
;
return
rm
;
}
public
string
Soap
(
string
action
)
{
if
(
action
==
"example"
)
{
WebService
.
SOAPEnvelope
envelope
=
new
WebService
.
SOAPEnvelope
();
envelope
.
Body
.
Method
=
"GetExample"
;
envelope
.
Body
.
Items
.
Add
(
"Price"
,
"1"
);
Context
.
Response
.
SetContentType
(
envelope
.
Version
==
WebService
.
SOAPVersion
.
Ver11
?
"text/xml"
:
"application/soap+xml"
);
return
WebService
.
SOAPEnvelope
.
CreateDocument
(
envelope
);
}
return
""
;
}
}
/// <summary>
/// 标准消息封装
...
...
Mozi.HttpEmbedded/WebService/SOAP.cs
浏览文件 @
fdafabf3
using
Mozi.HttpEmbedded.Generic
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Xml
;
using
Mozi.HttpEmbedded.Generic
;
namespace
Mozi.HttpEmbedded.WebService
{
class
SOAPEnvelope
public
class
SOAPEnvelope
{
public
string
xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
;
public
string
xsd
=
""
;
public
string
soap
=
""
;
public
string
encodingStyle
=
""
;
public
string
xsd
=
"http://www.w3.org/2001/XMLSchema"
;
public
string
encodingStyle
=
"http://www.w3.org/2001/12/soap-encoding"
;
/// <summary>
/// SOAP版本
/// </summary>
public
SOAPVersion
Version
=
SOAPVersion
.
Ver11
;
public
SOAPHeader
Header
{
get
;
set
;
}
public
SOAPBody
Body
{
get
;
set
;
}
public
SOAPEnvelope
()
{
Body
=
new
SOAPBody
();
}
/// <summary>
/// 构造xml文档
/// </summary>
/// <param name="envelope"></param>
/// <returns></returns>
public
static
string
CreateDocument
(
SOAPEnvelope
envelope
)
{
MemoryStream
ms
=
new
MemoryStream
();
XmlTextWriter
writer
=
new
XmlTextWriter
(
ms
,
System
.
Text
.
Encoding
.
UTF8
);
writer
.
WriteStartDocument
(
true
);
writer
.
WriteStartElement
(
envelope
.
Version
.
Prefix
,
"Envelope"
,
envelope
.
Version
.
Namespace
);
writer
.
WriteAttributeString
(
envelope
.
Version
.
Prefix
,
"encodingStyle"
,
null
,
envelope
.
encodingStyle
);
writer
.
WriteAttributeString
(
"xmlns"
,
"xsi"
,
null
,
envelope
.
xsi
);
writer
.
WriteAttributeString
(
"xmlns"
,
"xsd"
,
null
,
envelope
.
xsd
);
//header
if
(
envelope
.
Header
!=
null
)
{
writer
.
WriteStartElement
(
envelope
.
Version
.
Prefix
,
"Header"
,
""
);
if
(
envelope
.
Header
.
Childs
!=
null
&&
envelope
.
Header
.
Childs
.
Length
>
0
)
{
}
writer
.
WriteEndElement
();
}
//body
writer
.
WriteStartElement
(
envelope
.
Version
.
Prefix
,
"Body"
,
null
);
//bodyelements
writer
.
WriteStartElement
(
envelope
.
Body
.
Prefix
,
envelope
.
Body
.
Method
,
envelope
.
Body
.
Namespace
);
foreach
(
var
r
in
envelope
.
Body
.
Items
)
{
writer
.
WriteElementString
(
envelope
.
Body
.
Prefix
,
r
.
Key
,
null
,
r
.
Value
);
}
writer
.
WriteEndElement
();
writer
.
WriteEndElement
();
writer
.
WriteEndElement
();
writer
.
Flush
();
writer
.
Close
();
string
text
=
System
.
Text
.
Encoding
.
UTF8
.
GetString
(
ms
.
ToArray
());
ms
.
Close
();
return
text
;
}
//TODO 这种写法有问题,暂时无法生成完整的XML文档,后期再想办法解决
/// <summary>
/// 构造xml文档
/// </summary>
/// <param name="envelope"></param>
/// <returns></returns>
internal
static
string
CreateDocument1
(
SOAPEnvelope
envelope
)
{
XmlDocument
doc
=
new
XmlDocument
();
var
declare
=
doc
.
CreateXmlDeclaration
(
"1.0"
,
"utf-8"
,
"yes"
);
doc
.
AppendChild
(
declare
);
//envelope
var
nodeEnvelope
=
doc
.
CreateNode
(
XmlNodeType
.
Element
,
envelope
.
Version
.
Prefix
,
"Envelope"
,
envelope
.
Version
.
Namespace
);
var
encodingStyle
=
doc
.
CreateAttribute
(
"soap"
,
"encodingStyle"
,
envelope
.
encodingStyle
);
var
xsi
=
doc
.
CreateAttribute
(
"xmlns"
,
"xsi"
,
null
);
xsi
.
Value
=
envelope
.
xsi
;
var
xsd
=
doc
.
CreateAttribute
(
"xsd"
,
"xsd"
,
null
);
nodeEnvelope
.
Attributes
.
Append
((
XmlAttribute
)
xsi
);
nodeEnvelope
.
Attributes
.
Append
((
XmlAttribute
)
xsd
);
nodeEnvelope
.
Attributes
.
Append
((
XmlAttribute
)
encodingStyle
);
//header
if
(
envelope
.
Header
!=
null
)
{
var
nodeHeader
=
doc
.
CreateElement
(
envelope
.
Version
.
Prefix
,
"Header"
,
""
);
if
(
envelope
.
Header
.
Childs
!=
null
&&
envelope
.
Header
.
Childs
.
Length
>
0
)
{
}
nodeEnvelope
.
AppendChild
(
nodeHeader
);
}
//body
var
nodeBody
=
doc
.
CreateElement
(
envelope
.
Version
.
Prefix
,
"Body"
,
""
);
//bodyelements
var
nodeBodyMethod
=
doc
.
CreateElement
(
envelope
.
Body
.
Prefix
,
envelope
.
Body
.
Method
,
envelope
.
Body
.
Namespace
);
foreach
(
var
r
in
envelope
.
Body
.
Items
)
{
var
nodeItem
=
doc
.
CreateElement
(
envelope
.
Body
.
Prefix
,
r
.
Key
,
" "
);
nodeItem
.
InnerText
=
r
.
Value
;
nodeBodyMethod
.
AppendChild
(
nodeItem
);
}
nodeBody
.
AppendChild
(
nodeBodyMethod
);
nodeEnvelope
.
AppendChild
(
nodeBody
);
doc
.
AppendChild
(
nodeEnvelope
);
return
doc
.
OuterXml
;
}
/// <summary>
/// 解析SOAP文件
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
public
static
XmlDocument
ParseDocument
(
string
content
)
{
XmlDocument
doc
=
new
XmlDocument
();
doc
.
LoadXml
(
content
);
return
doc
;
}
}
class
SOAPHeader
public
class
SOAPHeader
{
SOAPHeaderChild
[]
Childs
{
get
;
set
;
}
public
SOAPHeaderChild
[]
Childs
{
get
;
set
;
}
}
class
SOAPHeaderChild
public
class
SOAPHeaderChild
{
public
string
actor
{
get
;
set
;}
public
string
mustUnderstand
{
get
;
set
;
}
//"0"|"1"
public
string
encodingStyle
{
get
;
set
;
}
}
class
SOAPBody
public
class
SOAPBody
{
public
SOAPFault
Fault
{
get
;
set
;
}
public
string
Prefix
=
"m"
;
public
string
Method
=
""
;
public
string
Namespace
=
"Mozi/WebService/Soap"
;
public
Dictionary
<
string
,
string
>
Items
=
new
Dictionary
<
string
,
string
>();
}
class
SOAPFault
public
class
SOAPFault
{
public
string
faultcode
{
get
;
set
;
}
public
string
faultstring
{
get
;
set
;
}
...
...
@@ -43,22 +163,25 @@ namespace Mozi.HttpEmbedded.WebService
/// <summary>
/// text/xml
/// </summary>
public
static
SOAPVersion
Ver11
=
new
SOAPVersion
(
"1.1"
,
"http://schemas.xmlsoap.org/soap/envelope/"
);
public
static
SOAPVersion
Ver11
=
new
SOAPVersion
(
"1.1"
,
"soap"
,
"http://schemas.xmlsoap.org/soap/envelope/"
);
/// <summary>
/// application/soap+xml
/// </summary>
public
static
SOAPVersion
Ver12
=
new
SOAPVersion
(
"1.2"
,
"http://www.w3.org/2003/05/soap-envelope"
);
public
static
SOAPVersion
Ver12
=
new
SOAPVersion
(
"1.2"
,
"soap12"
,
"http://www.w3.org/2003/05/soap-envelope"
);
public
static
SOAPVersion
Ver12Dotnet
=
new
SOAPVersion
(
"1.2"
,
"soap2"
,
"http://www.w3.org/2003/05/soap-envelope"
);
public
string
Version
{
get
{
return
_vervalue
;
}
}
public
string
Namespace
{
get
{
return
_namespace
;
}
}
public
string
Prefix
{
get
{
return
_prefix
;
}
}
protected
override
string
Tag
{
get
{
return
_vervalue
;
}
}
private
string
_vervalue
=
""
;
private
string
_namespace
=
""
;
private
string
_prefix
=
""
;
public
SOAPVersion
(
string
verValue
,
string
nameSpace
)
public
SOAPVersion
(
string
verValue
,
string
prefix
,
string
nameSpace
)
{
_vervalue
=
verValue
;
_prefix
=
prefix
;
_namespace
=
nameSpace
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录