How to: Configure WCF Service to Interoperate with ASP.NET Web Service Clients
2008-01-09 11:17
591 查看
ToconfigureaWindowsCommunicationFoundation(WCF)serviceendpointtobeinteroperablewithASP.NETWebserviceclients,usetheSystem.ServiceModel.BasicHttpBindingtypeasthebindingtypeforyourserviceendpoint.
YoucanoptionallyenablesupportforHTTPSandtransport-levelclientauthenticationonthebinding.ASP.NETWebserviceclientsdonotsupportMTOMmessageencoding,sotheSystem.ServiceModel.BasicHttpBinding.MessageEncodingpropertyshouldbeleftasitsdefaultvalue,whichisSystem.ServiceModel.WSMessageEncoding.Text.ASP.NetWebServiceclientsdonotsupportWS-Security,sotheSystem.ServiceModel.BasicHttpBinding.SecurityshouldbesettoTransport.
TomakethemetadataforaWCFserviceavailabletoASP.NETWebserviceproxygenerationtools(thatis,WebServicesDescriptionLanguageTool(Wsdl.exe),WebServicesDiscoveryTool(Disco.exe),andtheAddWebReferencefeatureinVisualStudio),youshouldexposeanHTTP/GETmetadataendpoint.
OptionallyenabletransportsecurityforthisserviceendpointbindingbysettingthesecuritymodeforthebindingtoTransport.Fordetails,pleaseseeTransportSecurity.
Addanewapplicationendpointtoyourservicehostusingthebindinginstancethatyoujustcreated.Fordetailsabouthowtoaddaserviceendpointincode,seetheHowto:CreateaServiceEndpointinCode.
EnableanHTTP/GETmetadataendpointforyourservice.FordetailsseeHowto:PublishMetadataforaServiceUsingCode.
Howto:SpecifyaServiceBindinginConfiguration.
OptionallyenabletransportsecurityforthisserviceendpointbindingconfigurationbysettingthesecuritymodeforthebindingtoTransport.Fordetails,seeTransportSecurity.
Configureanewapplicationendpointforyourserviceusingthebindingconfigurationthatyoujustcreated.Fordetailsabouthowtoaddaserviceendpointinaconfigurationfile,seetheHowto:CreateaServiceEndpointinConfiguration.
EnableanHTTP/GETmetadataendpointforyourservice.FordetailsseetheHowto:PublishMetadataforaServiceUsingaConfigurationFile.
C#
CopyCode
Xml
CopyCode
YoucanoptionallyenablesupportforHTTPSandtransport-levelclientauthenticationonthebinding.ASP.NETWebserviceclientsdonotsupportMTOMmessageencoding,sothe
TomakethemetadataforaWCFserviceavailabletoASP.NETWebserviceproxygenerationtools(thatis,
ToaddaWCFendpointthatiscompatiblewithASP.NETWebserviceclientsincode
CreateanewBasicHttpBindinginstanceOptionallyenabletransportsecurityforthisserviceendpointbindingbysettingthesecuritymodeforthebindingtoTransport.Fordetails,pleasesee
Addanewapplicationendpointtoyourservicehostusingthebindinginstancethatyoujustcreated.Fordetailsabouthowtoaddaserviceendpointincode,seethe
EnableanHTTP/GETmetadataendpointforyourservice.Fordetailssee
ToaddaWCFendpointthatiscompatiblewithASP.NETWebserviceclientsinaconfigurationfile
CreateanewBasicHttpBindingbindingconfiguration.Fordetails,seetheOptionallyenabletransportsecurityforthisserviceendpointbindingconfigurationbysettingthesecuritymodeforthebindingtoTransport.Fordetails,see
Configureanewapplicationendpointforyourserviceusingthebindingconfigurationthatyoujustcreated.Fordetailsabouthowtoaddaserviceendpointinaconfigurationfile,seethe
EnableanHTTP/GETmetadataendpointforyourservice.Fordetailsseethe
Example
ThefollowingexamplecodedemonstrateshowtoaddaWCFendpointthatiscompatiblewithASP.NETWebserviceclientsincodeandalternativelyinconfigurationfiles.C#
CopyCode
usingSystem; usingSystem.Collections.Generic; usingSystem.Text; usingSystem.ServiceModel; usingSystem.ServiceModel.Description; [ServiceContract] publicinterfaceIEcho { [OperationContract] stringEcho(strings); } publicclassMyService:IEcho { publicstringEcho(strings) { returns; } } classProgram { staticvoidMain(string[]args) { stringbaseAddress="http://localhost:8080/wcfselfhost/"; ServiceHosthost=newServiceHost(typeof(MyService),newUri(baseAddress)); //CreateaBasicHttpBindinginstance BasicHttpBindingbinding=newBasicHttpBinding(); //Addaserviceendpointusingthecreatedbinding host.AddServiceEndpoint(typeof(IEcho),binding,"echo1"); host.Open(); Console.WriteLine("Servicelisteningon{0}...",baseAddress); Console.ReadLine(); host.Close(); } }
Xml
CopyCode
<configuration> <system.serviceModel> <services> <servicename="MyService"behaviorConfiguration="HttpGetMetadata"> <endpointaddress="echo2"contract="IEcho"binding="basicHttpBinding"/> </service> </services> <behaviors> <serviceBehaviors> <behaviorname="HttpGetMetadata"> <serviceMetadatahttpGetEnabled="true"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration>
Ref:Howto:ConfigureWCFServicetoInteroperatewithASP.NETWebServiceClients
相关文章推荐
- Fiddler监听HttpClient-(Monitoring HTTP Output with Fiddler in .NET HTTP Clients and WCF Proxies - Rick Strahl's Web Log )
- How to take screenshot (thumbnail) of a web site with ASP.NET 2.0?
- Send and Receive JSON objects to Web Service Methods using jQuery AJAX in ASP.Net
- How to call webservices with ASP.NET at Run time?
- Replace JSON.NET with ServiceStack.Text in ASP.NET Web API
- 转载:Using JQuery with an ASP.NET webservice
- The service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application. Turn off ASP.NET compatibility mode in the web.config or add the AspNetCompatibilityRequirements attribute to the ser
- Virus Scanner induced bug with ASP.NET webservice application
- WCF VS ASPNET WEB SERVICE
- Adding OpenID to your web site in conjunction with ASP.NET Membership
- How to Migrate from WCF Web API to ASP.NET Web API
- asp.net<C#> web service Object moved to here.
- How to invoke Java web service in ASP.net using C#
- HOW TO: Configure SQL Server to Store ASP.NET Session State
- How to build Multi-Language Web Sites with ASP.NET 2.0 and VS.Net 2005
- How to build Multi-Language Web Sites with ASP.NET 2.0 and VS.Net 2005
- Passing Multiple Parameters to ASP.NET Web API With jQuery
- 转载 WCF VS ASPNET WEB SERVICE
- Interoperability with ASP.NET Web Services
- consume an asp.net webservice(upload a file to server) from java via soap