Silverlight dynamic WebService call

Source: Internet
Author: User

1. Configure IIS to bind an IP address

2. Reference WebService in SL

3. Write the following code where you need to call WebService:Code:

WCF:

WCF
1 basichttpbinding basicbinding = new basichttpbinding ();
2
3 custombinding binding = new custombinding (basicbinding );
4
5 bindingelement binaryelement = new binarymessageencodingbindingelement ();
6
7 // Delete the textmessageencodingbindingelement in the original elements set
8
9binding. elements. Remove (binding. elements [0]);
10
11 // Add binarymessageencodingbindingelement
12
13binding. elements. insert (0, binaryelement );
14
15 // WCF address
16
17 endpointaddress endpoint = new endpointaddress ("http: // 172.161.100/dynamicinvokewcf. Web/dynwcf. SVC ");
18
19 // create a WCF Client
20
21 dynwcfclient client = (dynwcfclient) activator. createinstance (typeof (dynwcfclient), binding, endpoint );
22
23client. doworkcompleted + = new eventhandler <doworkcompletedeventargs> (client_doworkcompleted );
24
25client. doworkasync ();
26
27

Traditional WebService:

WebService
1 basichttpbinding basicbinding = new basichttpbinding ();
2
3 custombinding binding = new custombinding (basicbinding );
4
5 bindingelement binaryelement = new binarymessageencodingbindingelement ();
6
7 endpointaddress endpoint = new endpointaddress ("http: // 172.161.100/dynamicinvokewcf. Web/asmx. asmx ");
8
9 asmxsoapclient client = (asmxsoapclient) activator. createinstance (typeof (asmxsoapclient), binding, endpoint );
10
11client. helloworldcompleted + = new eventhandler 12
13client. helloworldasync ();
14
15

In this way, you can call WebService dynamically. The servicereferences. clientconfig file is not required at all.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.