Frage

i am new to windows 8 metro application development , please let me help out in figuring out this issuse.

i want to consume web services in my metro application but the service reference url is dynamic.

i my app , the user will be given a provision to specify the url in a textbox , so i need to connect to that web service , that means the service reference url will be changing.

Till now i am connecting to web service in a traditional way like , giving a specific service reference by adding service reference and creating an instance and using that instance to call all the methods inside that web service .

but, 1) how should i consume web services if the service reference url is changing. 2)Access individual service methods inside that service (call that methods by passing some parameters as inputs).

Thanks in advance.

War es hilfreich?

Lösung

If you have the same service with different locations simply add it with "Add Service Reference..." and add the specified URL in the service client constructor:

var svc = new DataServiceClient("BasicHttpBinding_DataService", 
    "http://url.com/DataService.svc");

BasicHttpBinding_DataService is your (generated) binding name from the client config (automatically generated when doing "Add new Web Reference..."):

Example ServiceReferences.ClientConfig

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_DataService" maxBufferSize="2147483647"
                    maxReceivedMessageSize="2147483647">
                    <security mode="TransportWithMessageCredential" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://localhost:44300/Services/DataService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_DataService"
                contract="DataService.DataService" name="BasicHttpBinding_DataService" />
        </client>
    </system.serviceModel>
</configuration>

The code above can be used to change the address (e.g. https://localhost:44300/Services/DataService.svc) to one generated at runtime...

And have a look at this: http://blog.rsuter.com/?p=281

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top