WCF动态设置NameSpace for ServiceContract和DataContract,无需硬编码 [英] WCF Set NameSpace for ServiceContract and DataContract dynamically without hard coding
问题描述
你好,
[ServiceContract(命名空间 = < span class =code-string> http:// some url / )]
public < span class =code-keyword> interface ISample
{
[OperationContract]
double 添加( double i, double j);
[OperationContract]
double Sub( double i, double j);
[OperationContract]
复数AddComplexNo(Complex i,Complex j);
[OperationContract]
Complex SubComplexNo(Complex i,Complex j);
}
[DataContract(命名空间 = http:// some url / )]
public class 复杂
{
[DataMember]
public int Real { get ; set ; }
[DataMember]
public int 虚构{获得跨度>; set ; }
}
如何使用web.config应用程序设置键为NameSpace分配值?
我的意思是从web.config读取Namespace url并在此处设置为Namespace属性。
I尝试使用静态类,但它希望url值是硬编码的。
我可以在web.config中定义名称空间URL而不在此定义..?
相同service用于多个位置,因此,名称空间值必须以不同方式分配。
提前谢谢。
看看下面关于同一主题的讨论。
http://stackoverflow.com/questions/10585886/is-it-possible-to-dynamically-change-namespace-to -servicecontract-期间的运行时
Hello there,
[ServiceContract(Namespace = "http://some url/")]
public interface ISample
{
[OperationContract]
double Add(double i, double j);
[OperationContract]
double Sub(double i, double j);
[OperationContract]
Complex AddComplexNo(Complex i, Complex j);
[OperationContract]
Complex SubComplexNo(Complex i, Complex j);
}
[DataContract(Namespace = "http://some url/")]
public class Complex
{
[DataMember]
public int Real { get; set; }
[DataMember]
public int Imaginary { get; set; }
}
How to assign a value to the NameSpace using web.config app settings key ?
I mean read the Namespace url from web.config and set to the Namespace property here.
I tried using a static class, but it expects the url value to be hard coded.
Can I define namespace url in web.config itself without defining here..?
The same service is used for multiple locations, so , the namespace value has to be assigned differently.
Thank you in advance.
Have a look at below discussion on the same topic.
http://stackoverflow.com/questions/10585886/is-it-possible-to-dynamically-change-namespace-to-servicecontract-during-runtime
这篇关于WCF动态设置NameSpace for ServiceContract和DataContract,无需硬编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!