修改命名空间前缀Web Services c#
本文关键字:Services Web 前缀 命名空间 修改 | 更新日期: 2023-09-27 17:53:30
我们正在接收一个SOAP请求,我们不能全部修改它。因此,现在我们必须更改我们的web服务以适应调用。差不多了,期望它们的命名空间的前缀与生成的前缀不同,它不会击中方法,除非它是相同的:
这是我的Webservice:
[WebService(Namespace = "http://domain.co.za/")]
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
[System.ComponentModel.ToolboxItem(false)]
public class MyWebservice : System.Web.Services.WebService
{
[WebMethod]
public string PushMessage(object payload)
{
}
}
和它们发送的SOAP:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns0="http://domain.co.za/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<ns0:username soapenv:actor=""></ns0:username>
<ns0:password soapenv:actor=""></ns0:password>
</soapenv:Header>
<soapenv:Body>
<ns0:PushMessage>
<type>confirmation</type>
<autoRelease>true</autoRelease>
<payload>
<Confirmation>
<MessageEnvelope>
.
.
</MessageEnvelope>
</Confirmation>
</payload>
</ns0:PushMessage>
</soapenv:Body>
</soapenv:Envelope>
你可以看到他们正在使用ns0,由WDSL生成的是web,是否有办法强制我的命名空间生成ns0:而不是默认的web:
有没有办法从有效载荷元素中删除ns0/web ?它们不发送带有负载的名称空间,但是WDSL将其作为web:payload
生成。谢谢。
Try regex
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Text.RegularExpressions;
namespace Calendar
{
class Program
{
static void Main(string[] args)
{
string input =
"<?xml version='"1.0'" encoding='"UTF-8'" standalone='"no'"?>" +
"<soapenv:Envelope xmlns:soapenv='"http://schemas.xmlsoap.org/soap/envelope/'" xmlns:ns0='"http://domain.co.za/'" xmlns:xsd='"http://www.w3.org/2001/XMLSchema'" xmlns:xsi='"http://www.w3.org/2001/XMLSchema-instance'">" +
"<soapenv:Header>" +
"<ns0:username soapenv:actor='"'"> </ns0:username>" +
"<ns0:password soapenv:actor='"'"> </ns0:password>" +
"</soapenv:Header>" +
"<soapenv:Body>" +
"<ns0:PushMessage>" +
"<type>confirmation </type>" +
"<autoRelease>true </autoRelease>" +
"<payload>" +
"<Confirmation>" +
"<MessageEnvelope>" +
"</MessageEnvelope>" +
"</Confirmation>" +
"</payload>" +
"</ns0:PushMessage>" +
"</soapenv:Body>" +
"</soapenv:Envelope>";
string pattern = "(</?)(''w:)(''w)";
Regex expr = new Regex(pattern);
input = expr.Replace(input, "$1$3");
XDocument doc = XDocument.Parse(input);
}
}
}