从python spyne中托管的WCF webservice返回复杂数据结果

时间:2016-06-08 13:44:16

标签: c# python wcf spyne

我在从python spyne框架中托管的WCF webservice上的方法返回复杂类型时遇到问题。目前在C#方面我有这个代码示例:

var myBinding = new BasicHttpBinding();
var myEndpoint = new EndpointAddress("http://127.0.0.1:7706/FileOperationsBase");
var myChannelFactory = new ChannelFactory<FileOperationsBase>(myBinding, myEndpoint);

FileOperationsBase fileOp = myChannelFactory.CreateChannel();
var result = fileOp.FileExists("qweqweqweawdasdasdasdsa");
var result2 = fileOp.CreateFile("qweqweqweawdasdasdasdsa");

[ServiceContract]
public interface FileOperationsBase
{
    [OperationContract]
    bool FileExists(string filename);

    [OperationContract]
    MTFileInfo CreateFile(string filename);
}

[DataContract]
public class MTFileInfo
{
    [DataMember]
    public string Path { get; set; }
}

简单类型(bool)的第一个结果正如预期的那样工作,但在第二种情况下,我收到MTFileInfo,其属性设置为null。 Wireshark显示响应已收到,因此webservice本身不存在问题。

我做错了什么?

Wireshark response

application = Application([FileOperationsBase],
                       tns='http://tempuri.org/',
                       in_protocol=Soap11(),
                       out_protocol=Soap11()
                       )

if __name__ == '__main__':
# You can use any Wsgi server. Here, we chose
# Python's built-in wsgi server but you're not
# supposed to use it in production.
from wsgiref.simple_server import make_server

wsgi_app = WsgiMounter({
    '': application,
})

srv = make_server('0.0.0.0', 7706, wsgi_app)
srv.serve_forever()



class MTFileInfo(ComplexModel):
_type_info = [
    ('Attribute', String.customize(sub_name='Attributes')),
    ('CreationDate', DateTime),
    ('IsDirectory', Boolean),
    ('LastMoficationDate', DateTime),
    ('Path', String),
    ('Sha1', String),
    ('Size', Long)
]

class FileOperationsBase(ServiceBase):
@srpc(Unicode, _returns=MTFileInfo)
def CreateFile(path):
    print("CreateFileBEGIN")
    print(path)
    fileInfo = MTFileInfo()
    fileInfo.Attribute = "Normal"
    fileInfo.CreationDate = datetime.now()
    fileInfo.IsDirectory = True
    fileInfo.Path = "path"
    fileInfo.LastMoficationDate = datetime.now()
    fileInfo.Size = 9999
    fileInfo.Sha1 = "asdagfsdfgdfhdghgfjgfjgsfg"

    print("CreateFileAllEND")
    return fileInfo

0 个答案:

没有答案