Windows azure-appfabric: A simple servicebus example

Source: Internet
Author: User

Here we use the servicebus feature to expose a simple webget enabled service that runs on an intranet machine and is created by WCF.

Code List:

Iproduct. CS

 
Iproduct. CS[Servicecontract (namespace ="Http://sample.azure.com/appfabric/servicebus/ProductContract")]Public InterfaceIproduct {[operationcontract, webget] list <productinfo> lookupproducts ();}

Productservice. CS

Productservice. CS[Servicebehavior (name ="Productservice", Namespace ="Http://sample.azure.com/appfabric/servicebus/ProductService")]Public ClassProductservice: iproduct {PublicList <productinfo> lookupproducts () {list <productinfo> Infos =NewList <productinfo> ();For(IntI = 0; I <10; I ++) {Infos. Add (NewProductinfo {name ="N"+ I. tostring (), productid = I });}ReturnInfos ;}}

Host Service

HostStringServicenamespace = configurationmanager. receivettings ["Namespace"]; Uri address = servicebusenvironment. createserviceuri ("HTTPS", Servicenamespace ,"Productservice"); Webservicehost host =NewWebservicehost (Typeof(Productservice), address); host. open (); console. writeline (address. tostring (); console. writeline ("To close this service, please press any key."); Console. readkey (); host. Close ();

Configuration Service

 Config <? XML version ="1.0 "?> <Configuration> <startup> <supportedruntime version =" V4.0 "SKU =" . Netframework, version = v4.0 "/> </Startup> <system. servicemodel> <bindings> <! -- Application binding --> <nettcprelaybinding> <binding name =" Default "> <! -- Turn off client authentication so that client does not need to present credential through browser or fiddler --> <Security relayclientauthenticationtype =" None "/> </Binding> </nettcprelaybinding> <webhttprelaybinding> <binding name =" Default "> <! -- Turn off client authentication so that client does not need to present credential through browser or fiddler --> <Security relayclientauthenticationtype =" None "/> </Binding> </webhttprelaybinding> </bindings> <services> <service name =" Simpleservice. productservice "Behaviorconfiguration =" Default "> <Endpoint name =" Relayendpoint "Contract =" Sharedlib. iproduct "Binding =" Webhttprelaybinding "Bindingconfiguration =" Default "Behaviorconfiguration ="Sharedsecretclientcredentials "Address ="  "/> </Service> </services> <extensions> <bindingextensions> <Add name =" Nettcprelaybinding "Type =" Microsoft. servicebus. configuration. nettcprelaybindingcollectionelement, Microsoft. servicebus, version = 1.0.0.0, culture = neutral, publickeytoken = 31bf3856ad364e35 "/> <Add name =" Webhttprelaybinding "Type =" Microsoft. servicebus. configuration. webhttprelaybindingcollectionelement, Microsoft. servicebus, version = 1.0.0.0, culture = neutral, publickeytoken = 31bf3856ad364e35 "/> </Bindingextensions> <behaviorextensions> <Add name ="Transportclientendpointbehavior "Type =" Microsoft. servicebus. configuration. transportclientendpointbehaviorelement, Microsoft. servicebus, version = 1.0.0.0, culture = neutral, publickeytoken = 31bf3856ad364e35 "/> </Behaviorextensions> </extensions> <behaviors> <endpointbehaviors> <behavior name =" Sharedsecretclientcredentials "> <Transportclientendpointbehavior credentialtype =" Sharedsecret "> <Clientcredentials> <sharedsecret issuername =" Owner "Issuersecret =" ********** "/> </Clientcredenior> </transportclientendpointbehavior> </behavior> </endpointbehaviors> <servicebehaviors> <behavior name =" Default "> <Servicedebug httphelppageenabled =" False "Httpshelppageenabled =" False "/> </Behavior> </servicebehaviors> </behaviors> </system. servicemodel> <deleetask> <add key =" Namespace " Value =" *** "/> </Appsettings> </configuration>

Running effect:

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.