繁体   English   中英

WCF ServiceContract上的“名称”属性可以用于更改服务的URI吗?

[英]Can the “Name” attribute on a WCF ServiceContract be used to change the service's URI?

因此,可以使用DataContract的DataMember中的“名称”属性来控制生成的序列化json:

[DataContract(Name = "AuthenticationContract")]
public class AuthenticationContract
{
    [DataMember(Name = "first_name")]
    public string FirstName;

    [DataMember(Name = "last_name")]
    public string LastName;

}

结果是:

{"first_name":"frank","last_name":"rizzo"}


我希望ServiceContract上的Name属性可以执行类似的操作:

[ServiceContract(Name="nameapi")]
public class NameAuthenticationService : INameAuthenticationService    
{
    [OperationContract]
    public string GetName()....
}


所以代替这个

http://localhost:49531/NameAuthenticationService/GetName

...我可以用这个

http://localhost:49531/nameapi/GetName


这可能吗?

不,ServiceContractAttribute.Name控制您从服务发布的WSDL公开的<portType> 您要做的就是更改服务的基址,您应该能够在服务的.config文件中对其进行设置(或者,如果您是自托管的,则可以手动进行设置)。 参见http://msdn.microsoft.com/zh-cn/library/ms788982(v=VS.85).aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM