什么是添加名称和命名空间为DataContract办? [英] What does adding Name and Namespace to DataContract do?

查看:137
本文介绍了什么是添加名称和命名空间为DataContract办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打过电话叫注册一个WebInvoke方法,它返回发生在一个User对象,而是立即返回该对象。它看起来像以下内容:

I tried calling a WebInvoke method called Register which returns takes in a User object and immediately just returns that object. It looks like the following:

User Register(User user)
{
    return user;
}



我不知道什么名称和命名空间的属性做了DataContract属性时://本地主机:8081 /用户/注册例如:

我想问的原因是因为我最初有我的阶级与DataContract装饰属性是这样的:

The reason I ask is because I initially had my class decorated with the DataContract attribute like this:

[DataContract]
public class User
{
   // Properties
}

当我打开了小提琴手,并派出一个POST请求,它说不准的方法,但是当我改变DataContract为:

When I opened up Fiddler, and sent a Post request, it said method not allowed, but when I changed DataContract to:

[DataContract(Name="User", Namespace="")]

它的工作。

推荐答案

这些属性控制在WSDL元素的名称空间和名称。在代码中最重要的部分是命名空间=:这将覆盖默认的命名空间(http://tempuri.org),并将其值设置为空URL。 // tempuri:

These properties control the namespace and name of the element in the WSDL. The important part in your code is the Namespace="": this will override the default namespace (http://tempuri.org) and set its value to an empty URL.

在最后,用户类将在WSDL从 HTTP改名.ORG /用户以简单的用户。

In the end, the User class will be renamed in the WSDL from http://tempuri.org/User to simply User.

这篇关于什么是添加名称和命名空间为DataContract办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆