我在 c# 中设置了一个 Web 服务,他们使用 perl Soap::Lite 调用它。我试图让程序删除命名空间前缀,而是将完整的命名空间定义为操作标记中的 xmlns 属性。生成的请求如下所示
<soap:Envelope
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:tns="https://mynamespace.org"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<tns:myMethod>
<name xsi:type="s:string">First Cycle</name>
<desc xsi:type="s:string"> The Description</desc>
</tns:myMethod>
</soap:Body>
</soap:Envelope>
生成上述请求的代码是这样的
use strict ;
use warnings ;
use SOAP::Lite +trace => [ transport => sub { print $_[0]->as_string } ];;
my $ns = "https://mynamespace.org";
my $HOST = "http://localhost:54387/WebService.asmx";
my $wsdl = "http://localhost:54387/WebService.asmx?wsdl";
my $soap = SOAP::Lite->service($wsdl);
$soap->default_ns($ns);
my $som = $soap->myMethod(
'First Cycle', 'The Description'
);
die $som->fault->{ faultstring } if ($som->fault);
print $som->result, "\n";
上面的参数在 Web 服务中显示为 null,因为 C# 将参数解析为位于不同的命名空间中。而不是前缀,我希望动作看起来像这样
<myMethod xmlns="https://mynamespace.org">
我试过使用
my $soap = SOAP::Lite->new( proxy => $HOST);
而不是服务描述。它有效,但参数是这样的变化<c-sysgen3 xsi:type="s:string"><c-sysgen3>
我希望请求看起来像这样
<soap:Envelope
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:tns="https://mynamespace.org"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<myMethod xmlns="https://mynamespace.org">
<name xsi:type="s:string">First Cycle</name>
<desc xsi:type="s:string"> The Description</desc>
</myMethod>
</soap:Body>
</soap:Envelope>
或者像这样
<soap:Envelope
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:tns="https://mynamespace.org"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<tns:myMethod>
<tns:name xsi:type="s:string">First Cycle</tns:name>
<tns:desc xsi:type="s:string"> The Description</tns:desc>
</tns:myMethod>
</soap:Body>
</soap:Envelope>
我应该提一下,我不允许在 perl 中显式定义元素标签,例如
$soap->call('myMethod',
SOAP::Data->name('name')->value( 'First Cycle' ),
SOAP::Data->name('desc')->value('The Description') );
请帮忙 (-:
编辑:我的 perl 版本是 5.28.1,SOAP::Lite 的版本是 1.27 我也使用 .net framework 4.5
编辑:我可能应该添加我的网络服务实现
namespace WebService
{
[WebService(Namespace = "https://mynamespace.org")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class SoapService : System.Web.Services.WebService
{
[WebMethod]
public string myMethod(string name, string desc)
{
// Implementation here
}
}
}