[英]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.