开发者

WCF REST WebService - Can't change ServiceContract XML namespace

Kind of new to WCF and everything that surrounds it.

I would like to change the default http://schemas.datacontract.org/2004/07/WebService namespace which is menadatory to my XML based webservice requests to something else, but unfortunately was not able to find anything to solve this.

I've the following:

[ServiceContract(Namespace = "http://www.mywebservice.com/webservice")]
....
public class WebService

But when testing my webservice POST based method开发者_运维问答s, I still cannot use the new namespace (but the old one still works) for XML based requests. am I missing something here?

Thanks in advance!

Mikey


It's not clear which WCF "REST" flavor framework you are using but if you have your classes marked with the DataContract attribute, set its Namespace property on each class to the namespace you want. If they're not marked then add that attribute with your namespace as shown below. This should replace the default namespace being generated for data contracts with your namespace.

[DataContract(Namespace="http://www.mywebservice.com/webservice")]
public class YourDataClass
{
     //something applicable...
}


You need the Namespace on both the ServiceContract attribute on the interface and the ServiceBehavior attribute on the implementation class:

[ServiceBehavior(Namespace = "http://www.mywebservice.com/webservice")]
public class WebService
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜