如何确定 WCF 数据服务的客户端引用的 URL?

发布于 2024-12-09 13:45:16 字数 913 浏览 0 评论 0 原文

要在 Windows Phone 上访问 OData,请执行以下操作:

// Declare the data service objects and URIs.
NorthwindEntities context;
Uri northwindUri =
    new Uri("http://services.odata.org/Northwind/Northwind.svc/");
DataServiceCollection<Customer> customers;

// Initialize the context and the binding collection 
context = new NorthwindEntities(northwindUri);
customers = new DataServiceCollection<Customer>(context);

// Define a LINQ query that returns all customers.
var query = from cust in context.Customers
            select cust;

// Register for the LoadCompleted event.
customers.LoadCompleted
    += new EventHandler<LoadCompletedEventArgs>(customers_LoadCompleted);

// Load the customers feed by executing the LINQ query.
customers.LoadAsync(query);

但我已经从服务引用中知道了 URL。

我不能将其传递给 URI 参数吗?

是否有一种简单的方法来访问其配置的 URL?

这是一个好主意吗?

To access OData on Windows Phone you do this:

// Declare the data service objects and URIs.
NorthwindEntities context;
Uri northwindUri =
    new Uri("http://services.odata.org/Northwind/Northwind.svc/");
DataServiceCollection<Customer> customers;

// Initialize the context and the binding collection 
context = new NorthwindEntities(northwindUri);
customers = new DataServiceCollection<Customer>(context);

// Define a LINQ query that returns all customers.
var query = from cust in context.Customers
            select cust;

// Register for the LoadCompleted event.
customers.LoadCompleted
    += new EventHandler<LoadCompletedEventArgs>(customers_LoadCompleted);

// Load the customers feed by executing the LINQ query.
customers.LoadAsync(query);

But I already know the URL from the service reference.

Can't I just pass that to the URI argument?

Is there an easy way to access it's configured URL?

Is this a good idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愿得七秒忆 2024-12-16 13:45:16

如果您定义了服务客户端,则可以通过执行以下操作来获取使用的 URI:

client.Endpoint.Address.Uri

在 app.config 中定义了服务引用:

<client>
  <endpoint address="http://localhost:36294/Services/Service1.svc"
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
      contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
</client>

如果您的应用程序中已经有此内容(对于 Web 应用程序为 web.config)。那么您根本不需要定义端点,因为它已经存在并且将在实例化时被抓取。

假设该服务是 WCF 服务,并且通过“添加服务引用...”添加引用

If you have a service client defined you can get the URI used by doing:

client.Endpoint.Address.Uri

In the app.config the service reference is defined:

<client>
  <endpoint address="http://localhost:36294/Services/Service1.svc"
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
      contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
</client>

If you have this in your application already (web.config for web app). Then you dont need to define the endpoint at all as it already exists and will be grabbed upon instantiation.

This is assuming that the service is a WCF service and a reference is added via 'Add Service Reference...'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文