开发者

How to determine the URL of a WCF Data Service's client reference?

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?


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...'

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜