简体   繁体   English

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

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

So the "Name" attribute in a DataContract's DataMember can be used to control the resulting serialized json: 因此,可以使用DataContract的DataMember中的“名称”属性来控制生成的序列化json:

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

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

}

results in: 结果是:

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


I was hoping that the Name attribute on a ServiceContract would do something similar: 我希望ServiceContract上的Name属性可以执行类似的操作:

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


So that instead of this 所以代替这个

http://localhost:49531/NameAuthenticationService/GetName

... I could use this ...我可以用这个

http://localhost:49531/nameapi/GetName


Is this possible? 这可能吗?

No, ServiceContractAttribute.Name controls the <portType> exposed by the WSDL you publish from the service. 不,ServiceContractAttribute.Name控制您从服务发布的WSDL公开的<portType> What you want to do is change the base address of the service, which you should be able to set in the service's .config file (or set it manually if you're self-hosting). 您要做的就是更改服务的基址,您应该能够在服务的.config文件中对其进行设置(或者,如果您是自托管的,则可以手动进行设置)。 See http://msdn.microsoft.com/en-us/library/ms788982(v=VS.85).aspx 参见http://msdn.microsoft.com/zh-cn/library/ms788982(v=VS.85).aspx

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

相关问题 具有相同类的自定义ServiceContract的WCF数据服务 - WCF Data Service with a custom ServiceContract in the same class 我可以在WCF ServiceContract中公开数据成员吗? - Can I expose a data member in a WCF ServiceContract? 部署授权属性使用的WCF服务 - Dispose WCF service used by authorize attribute 配置WCF,其中ServiceContract和服务实现位于单独的程序集中 - Configure WCF where ServiceContract and service implementation are in separate assemblies 共享WCF服务和客户端之间的接口(标记为W / ServiceContract) - Sharing Interfaces Between a WCF Service and Client (marked w/ ServiceContract) 从单个服务托管多个WCF ServiceContract实现 - Hosting multiple WCF ServiceContract implementations from a single service 如何向WCF ServiceContract命名空间添加前缀 - How can I add a prefix to a WCF ServiceContract Namespace WCF如何将ServiceContract / OperationContract转换为可以序列化的消息? - How does WCF turn a ServiceContract/OperationContract into a Message that can be serialized? WCF中的DataContract / ServiceContract的版本控制 - Versioning of DataContract/ServiceContract in WCF WPF API可以安全地用在WCF服务中吗? - Can the WPF API be safely used in a WCF service?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM