2012-04-29 84 views
14

我创建了一个WCF服务,但服务WSDL不显示我的类(复杂类型)。复杂类型不可用wcf wsdl

下面是服务:

[ServiceContract] 
public interface IFedexService 
{ 
    [OperationContract] 
    ShipmentReply CreateMultiFedExShipment(RxRdShipment shipment); 

    [OperationContract] 
    ShipmentReply CreateFedExShipment(RxRdShipment shipment); 
} 

我的类定义是:

[DataContract] 
public class ShipmentReply 
{ 
    [DataMember] 
    public string ReferenceNumber { get; set; } 

    [DataMember] 
    public string MasterTrackingNumber { get; set; } 

    [DataMember] 
    public List<ReplyPackage> Packages { get; set; } 

    [DataMember] 
    public bool Response { get; set; } 

    [DataMember] 
    public RxNotification Notification { get; set; } 
} 

我的问题是我没有WSDL找到这个ShipmentReply类。我的问题是什么?

谢谢 Arefin

回答

28

是的,这是正常的WCF。默认情况下,WCF将仅显示WSDL本身中的操作 - 数据结构记录在链接到WSDL文件的XSD文件中。

我敢打赌,如果你看看你的WSDL,你会看到类似这样的东西几乎是在您的WSDL的顶部:

<xsd:schema targetNamespace="http://tempuri.org/Imports"> 
    <xsd:import schemaLocation="http://localhost:8000/HelloIndigo?xsd=xsd0" 
       namespace="http://tempuri.org/" /> 
    <xsd:import schemaLocation="http://localhost:8000/HelloIndigo?xsd=xsd1" 
       namespace="http://schemas.microsoft.com/2003/10/Serialization/" /> 
    <xsd:import schemaLocation="http://localhost:8000/HelloIndigo?xsd=xsd2" 
       namespace="http://schemas.datacontract.org/2004/07/WCF_Simple_Service" /> 
</xsd:schema> 

这些链接所需的XSD文件 - 在类型URL到您的浏览器中,其中一个(最有可能是数量最多的一个 - 但不一定是那个)将包含您的复杂类型定义。

尝试在浏览器这个URL(适应港口和实际的URL你有什么):

http://localhost:8080/HelloIndigo?xsd=xsd2 

这应该给你的XSD您的复杂类型

这个功能引起了一些问题在过去的几年中,一些客户无法处理这种(100%正确和完美的)语法。因此,在.NET 4.5中,WCF将有一个新参数(...?singlewsdl)输出包括所有XSD元素的整个WSDL - 有关更多信息,请参阅What's new in WCF 4.5? A single WSDL file

+0

你是对的,谢谢。你能告诉我一件事..当我使用一个不是datacontract的类的属性时,那么我必须使用__BackingField,是否有任何好处或你知道的其他东西.. – 2012-04-29 11:20:43

+0

如果你正在使用'[DataContract] &[DataMember]属性 - 在需要的任何地方使用它们!这是最简单和最安全的方式 - 其他任何事情都是黑客。 – 2012-04-29 11:46:46

+1

非常感谢。 – 2012-04-30 09:38:19