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: