什么原因导致Web服务URL和命名空间之间的区别吗? [英] What causes a difference between a web service URL and a namespace?

查看:162
本文介绍了什么原因导致Web服务URL和命名空间之间的区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含Web服务的ASP.NET Web项目。当我运行的服务它带给我要显示所有被暴露的方法,使用类似 http://api.example.com/game/service.asmx

I have an ASP.NET web project that contains a Web Service. When I run the service it brings me to a page showing all the methods that are exposed, using a URL similar to http://api.example.com/game/service.asmx.

在为Web服务的代码有一些具有以下属性的方法:

In the code for the Web Service there are methods that have the following attributes:

    [WebService(Namespace = "http://webservices.example.com/GameServices/Game1")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Game1 : System.Web.Services.WebService
    {
        // code 
    }

我在为什么用WebService属性的类命名空间的路径Web服务不同的有点糊涂了。其中该命名空间来自哪里?难道仅仅是由?

I am a little confused over why the namespace on a class with the webService attribute is different to the path to the web service. Where is that namespace coming from? Is it just made up?

推荐答案

是的,它是由

这听起来很傻,但这是事实。那里指定的命名空间,在你的代码,将上获得尽可能为特定的Web服务请求和响应交换的XML文档中使用。如果你把一个网络跟踪程序上线,你会看到在消息中使用来回的命名空间的字符串。在Web服务,您的应用程序无需与命名空间关注自身,通常。该Web服务库通常需要照顾它。

That sounds silly, but it's true. The namespace specified there, in your code, will be used on the XML documents that get exchanged as requests and responses for that particular web service. If you put a network trace program on the wire, you'd see those namespace strings used in the messages back and forth. In webservices, Your app need not concern itself with the namespace, usually. The webservices library usually takes care of it for you.

是一个HTTP URL命名空间是不需要的,但人们往往使用HTTP的URL。这可能是最混乱的你的一部分来源。
XML命名空间的IETF建议表明,它应该是的一个URI 的,但该URI不必是HTTP URI,并且实际上它不需要任何连接到它的网络协议 。

The namespace is not required to be an HTTP URL, though often people use HTTP URLs. This may be the source of most of the confusion on your part. The IETF Recommendation for XML namespaces suggests that it should be a URI, but that URI need not be an HTTP URI, and in fact it need not have any "network protocol" attached to it.

该命名空间是......一个字符串。它被用作一种简单的方式来限定在XML模式信息。想想这就像一个人的姓氏。你可能知道几个人名叫克里斯。您可以通过自己的姓氏区别开来。

The namespace is... a string. It is used as a simple way to qualify information in an XML schema. Think of it like a person's surname. You might know several people named "Chris". You distinguish them by their last names.

类似地,可以在许多不同的XML文档和模式中使用的元素名称为ID。应用程序(和人民太)可以在通过他们的XML命名空间使用qname的ID的许多不同的元素加以区分。

Similarly, the element name "id" may be used in many different XML documents and schema. Applications (and people too) can distinguish between the many different elements that use the qname "id" via their xml namespace.

通常情况下,信息建筑师将指定一个文档或Web服务作为一个URI,它是分层次的,独一无二的拥有组织中的XML命名空间,以及相关的意的XML文档中的信息。 (在一个小组织的信息建筑师仅仅是一个开发者。)例如 http://mycompany.com/services/2013/客户可能是MyCompany的命名空间,在2013年创建的有关服务,并专门的客户服务。

Typically, an "information architect" will specify the XML namespace for a document or a webservice as a URI that is hierarchical, unique to the owning organization, and relevant to the meaning of the information in the XML document. (In a small organization the "info architect" is just a developer.) For example http://mycompany.com/services/2013/customer might be a namespace for MyCompany, created in 2013 and pertaining to services, and specifically the customer service.

在我看来,有没有真正的理由使用的http:// 作为URI方案为XML命名空间,除非你打算做可在该HTTP URI文档。你也可以同样用瓮:mycompany.com/services/2013/customer作为XML命名空间。事实上,它可能会更好,因为它表明它只是一个名字,它不是一个定位器。 (不是一个网络地址)。

In my opinion, there's no real reason to use http:// as the scheme in the URI for an XML namespace, unless you plan to make documentation available at that HTTP URI. You could just as well use urn:mycompany.com/services/2013/customer as the XML namespace. In fact it might be better, because it indicates it's just a name, it's not a locator. (not a web address).

我通常使用一瓮,用前缀金塔:的方案,以表明该命名空间是一个简单的名,唯一标志。

I normally use a URN, prefixed with urn: as the scheme, to indicate that the namespace is simply a name, a uniquifier.

修改
有针对的URNs 。其基本格式为:

金塔:其中; NID>:< NSS>

urn:<NID>:<NSS>

...其中NID是命名空间ID,的一组特殊批准串和NSS是一个特定的命名空间字符串。全国免疫日批准的名单包括ISBN,UUID,IETF和大约20人 - 每个人心中都有一个不同的IETF RFC定义的特定含义。

...where NID is a namespace id, one of a set of special, approved strings and NSS is a namespace-specific string. The list of approved NIDs includes isbn, uuid, ietf, and about 20 others - each one has a specific meaning defined by a distinct IETF RFC.

尽管对全国免疫日活动的规则,很多人根本懒得接轨,并在地方NID使用其域名铸造自己的URN。如mycompany.com。 (这是我做的,常)。

Despite the rules about NIDs, many people simply don't bother to conform, and coin their own URNs using their domain name in place of the NID. eg "mycompany.com". (This is what I do, often).

然后,它是你的选择你想怎么进一步限定名称。您可以指定服务,以表示Web服务。有些人使用的年份和月份该服务是在一个命名空间中展开。这可以让你更新服务,并使用不同的日期不同元素之间的区别。下面这个命名约定的一个例子XML命名空间可能是:

Then it's your choice how you want to qualify the name further. You can specify "services", to indicate a web service. Some people use the year and month the service was launched in a namespace. This allows you to update the service, and use a different date to distinguish between different elements. An example XML namespace following this naming convention might be:

 urn:mycompany.com:services:2011:04:Game

这是什么样的 RFC 2141 称之为无效URN因为我没有使用注册NID。但是,我的服务宗旨。这是一个简单的步骤通过向它改造成一个有效URN在 FDC NID,由 RFC定义4198

This is what RFC 2141 calls an "invalid URN" because I didn't use a registered NID. But it serves my purpose. It is a simple step to transform it into a "valid URN" by applying the fdc NID, defined by RFC 4198.

 urn:fdc:mycompany.com:services:2011:04:Game

请参阅如何更好的是什么?

See how much better that is?

在最后,大多数人只是建立自己的命名约定,这东西是有道理的,它们的用途,对XML数据的内部和合作伙伴的消费者。

In the end, most people just establish their own naming convention, something that makes sense for their uses, for internal and partner consumers of the XML data.

这篇关于什么原因导致Web服务URL和命名空间之间的区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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