我尝试将复杂的数据类型从Perl发送到.NET WCF。简单类型工作正常。
WCF 接口:
[ServiceContract]
public interface IWebservice
{
[WebInvoke(RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped)]
[OperationContract]
void PutColledtedData(ServerInfoCollection Serverdata);
}
数据类型的类
[DataContract (Name="ServerInfoCollection")]
public class ServerInfoCollection
{
[DataMember]
public string OperatingSystem { get; set; }
[DataMember]
public string OS_Version { get; set; }
[DataMember]
public string OS_Architecture { get; set; }
[DataMember]
public string OS_ServicePack { get; set; }
private long pysicalMem = 0;
[DataMember]
public long PysicalMemory
{
get { return pysicalMem; }
set { pysicalMem = value; }
}
[DataMember]
public List<FileSystem> Filesystems { get; set; }
[DataMember]
public string Manufacturer { get; set; }
[DataMember]
public List<Interface> Interfaces { get; set; }
[DataMember]
public string Model { get; set; }
public ServerInfoCollection()
{
Filesystems = new List<FileSystem>();
Interfaces = new List<Interface>();
}
[DataMember]
public string Hostname { get; set; }
[DataMember]
public string Alias { get; set; }
[DataMember]
public string WindowsDomain { get; set; }
[DataMember]
public string WindowsDomainRole { get; set; }
[DataMember]
public DateTime InstallDate { get; set; }
[DataMember]
public int LogicalProcessors { get; set; }
[DataMember]
public int PhysicalProcessors { get; set; }
[DataMember]
public IPAddress MonitoringIP { get; set; }
}
肥皂恩文爱发送到服务器
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<PutColledtedData xmlns="http://tempuri.org/">
<Serverdata>
<OperatingSystem />
<OS_Version>13.1 (Bottle)</OS_Version>
<OS_Architecture>x86_64</OS_Architecture>
<OS_ServicePack>13.1</OS_ServicePack>
<PysicalMemory>6272438272</PysicalMemory>
<Manufacturer>VMWare</Manufacturer>
<Model />
<Hostname>myServerName</Hostname>
<Alias>myServerName</Alias>
<WindowsDomain />
<WindowsDomainRole />
<InstallDate>Thu Nov 27 12:21:33 2014</InstallDate>
<LogicalProcessors>4</LogicalProcessors>
<PhysicalProcessors>4</PhysicalProcessors>
</Serverdata>
</PutColledtedData>
</soap:Body>
</soap:Envelope>
Perl 代码:
use strict;
use SOAP::Lite trace => 'debug', maptype => {};
use Sys::Hostname;
my $serverinfos={
OperatingSystem=>'',
OS_Version=>'',
OS_Architecture=>'',
OS_ServicePack=>'',
PysicalMemory=>'',
Manufacturer=>'',
Model=>'',
Hostname=>'',
Alias=>'',
WindowsDomain=>'',
WindowsDomainRole=>'',
InstallDate=>'',
LogicalProcessors=>'',
PhysicalProcessors=>'',
Interfaces=>'',
Filesystems=>'',
};
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;
$SOAP::Constants::DO_NOT_USE_CHARSET = 1;
my $uri="http://tempuri.org/";
my $url ='https://myserver.her.de:1986/Webservice/Webservice.svc';
my $xmlns = 'http://schemas.datacontract.org/2004/07/com.aii.observer';
my $soap = SOAP::Lite
-> uri($uri)
-> on_action(sub { sprintf '%sIObserverWebservice/%s', @_ })
-> proxy($url, ssl_opts => [ SSL_verify_mode => 0 ] )
->autotype(0)
->readable('false');
# some stuff to initialize the serverinfos Hash truncated
my $param=SOAP::Data->name( "Serverdata"=>SOAP::Data->value(
SOAP::Data->name(OperatingSystem=>''),
SOAP::Data->name(OS_Version=>$serverinfos->{OS_Version}),
SOAP::Data->name(OS_Architecture=>$serverinfos->{OS_Architecture}),
SOAP::Data->name(OS_ServicePack=>$serverinfos->{OS_ServicePack}),
SOAP::Data->name(PysicalMemory=>$serverinfos->{PysicalMemory}),
SOAP::Data->name(Manufacturer=>$serverinfos->{Manufacturer}),
SOAP::Data->name(Model=>''),
SOAP::Data->name(Hostname=>$serverinfos->{Hostname}),
SOAP::Data->name("Alias")->value($serverinfos->{Alias}),
SOAP::Data->name(WindowsDomain=>''),
SOAP::Data->name(WindowsDomainRole=>''),
SOAP::Data->name(InstallDate=>$serverinfos->{InstallDate}),
SOAP::Data->name(LogicalProcessors=>$serverinfos->{LogicalProcessors}),
SOAP::Data->name(PhysicalProcessors=>$serverinfos->{PhysicalProcessors})
)
);
my $res=$soap->call('PutColledtedData',$param);
在Webservice中,我得到了ServerInfoCollection的Obekct,但所有属性都是空的。
我的误会在哪里??
编辑:添加了 Perl 代码,将网络调用添加到服务接口
你的perl代码serverinfos值是空的。如果已填写,则服务器答案正常。