SUMMARY: How to ENABLE WCF to work properly with BINDINGS
Examples will include FLEX 4, JAVASCRIPT, AJAX, JSON
NOTICE: this example is written for the .net 4.0 FRAMEWORK
DISCLAIMER: WCF is very sensative, if you are working with .net 3.5 or lower please find another example
how to connet jquery and javascript to WCF SERVICE and use JSON TO COMMUNICATE
with out using the factory class in the service file..
Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory"
summary:
THESE PRINT SCREENS (IN THE HYPERLINK DOCUMENT (XPS)) SHOW HOW TO CREATE A HELLO WORLD WCF APPLICATION WHICH CAN COMMUNCATE WITH
JAVASCRIPT, JQUERY AND FLEX 4 (USING DATA SERVICES) WHILE USING THE JSON PROTOCOL FOR THE COMMICATION LAYER.
REFERENCE:
WCF HELLOWORLD APPLICATION WRITTEN FOR WCF 4.O
HELLO WORLD APPLICATION FOR WCF
(HOW TO CREATE WCF SERVICES WITH NAMESPACES)
(HOW TO CREATE .NET 4.0 SVC FILES TO COMMUNICATE TO JAVASCRIPT USING JSON)
TWO OTHER WEB PAGES I HAVE WRITTEN INCLUDE
HOW TO ARTICLE #1>
ADOBE FLEX AND DOTNET XML WEB SERVICES RETURNING XML RESULTS mx WebService TAG
HOW TO ARTICLE #2>
wcf4 services https binding visual studio 2010 template
JULY 27, 2010
TO VIEW SOME OF THESE PICTURES IN THE DOCUMENT
YOU MAY WANT TO
"ZOOM YOUR BROWSER TO 200% or more"
WEB.CONFIG FILE....please be sure you pay attention to your
OTHER FILES such as services (make sure you pay attention to namespaces)
NOTICE: THE JAVASCRIPT/JQUERY Will communicate on a binding name (CASE SENSATVE)
var globalDjlScormWebServiceUrl = 'myHelloWorld.svc/webHttpBinding/'; var globalDjlScormWebServiceUrl2 ='Service.svc/webHttpBinding/';
this document is created with the windows printer which comes native to office 2010 . YOU CAN download the viewer from
CLICK ON THE NEXT LINK (xps DOCUMENT) TO SEE ALL THE PRINT SCREENS
as you go THROUGH THE DOCUMENT ABOVE "PAY ATTENTION TO THE NAMESPACES\\
ALSO NOTICE ALL THE ASPNET COMPATIBLITY AND TAGS WHICH ARE NOT NEEDED IN THE INTERFACE FILE
WebApplication.myHelloWorld BASE NAMESPACE APPEARS IN 3 DIFFERENT FILES (.VB, SVC, INTERFACE.VB)
WebServicesTest.Service BASE NAMESPACE APPEARS IN 3 DIFFERENT FILES (.VB, SVC, INTERFACE.VB)
TO SEE WHAT NEEDS TO BE DONE FOR HTTPS
see this webpage:
HERE IS THE WEB.CONFIG FILE
(NAMESPACE and HTTPS configuration are convered on the next page)
<system.serviceModel> <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/> <services>
<!-- if using a namespace the service file(svc) needs to change as well is the class and interface files too-->
<service name="WebApplication.myHelloWorld" behaviorConfiguration="myHelloWorldServiceBehavior"> <!-- FLEX 4 --> <endpoint address="basicHttpBinding" contract="WebApplication.ImyHelloWorld" binding="basicHttpBinding"> </endpoint> <!-- JAVASCRIPT /JQUERY/ AJAX --> <endpoint address="webHttpBinding" behaviorConfiguration="myHelloWorldEndPointBehavior" contract="WebApplication.ImyHelloWorld" binding="webHttpBinding"> </endpoint> <!-- OTHER BINDINGS --> <endpoint address="wsHttpBinding" contract="WebApplication.ImyHelloWorld" binding="wsHttpBinding"> </endpoint> </service> <!-- if using a namespace the service file(svc) needs to change as well is the class and interface files too--> <service name="WebServicesTest.Service" behaviorConfiguration="myHelloWorldServiceBehavior"> <!-- FLEX 4 --> <endpoint address="basicHttpBinding" contract="WebServicesTest.IService" binding="basicHttpBinding"> </endpoint> <!-- JAVASCRIPT /JQUERY/ AJAX --> <endpoint address="webHttpBinding" behaviorConfiguration="myHelloWorldEndPointBehavior" contract="WebServicesTest.IService" binding="webHttpBinding"> </endpoint> <!-- OTHER BINDINGS --> <endpoint address="wsHttpBinding" contract="WebServicesTest.IService" binding="wsHttpBinding"> </endpoint> </service> </services> <behaviors> <serviceBehaviors> <behavior name="myHelloWorldServiceBehavior"> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="myHelloWorldEndPointBehavior"> <webHttp/> <enableWebScript/> </behavior> </endpointBehaviors> </behaviors> </system.serviceModel>
as YOU NOTICE THIS DOES NOT LOOK LIKE A 3.5 WCF WEBCONFIG FILE IT LOOKS MUCH SIMPLER..
IMYHELLOWORLD.VB
(NAMESPACE for PROPER WSDL locations are convered on the next page)
Imports System.ServiceModel
Namespace WebApplication <ServiceContract()> Public Interface ImyHelloWorld
<OperationContract()> Function CallHelloWorld() As String
End Interface End Namespace
MYHELLOWORLD.VB
(NAMESPACE for PROPER WSDL locations are convered on the next page)
Namespace WebApplication Public Class myHelloWorld
Implements ImyHelloWorld
Public Function CallHelloWorld() As String Implements ImyHelloWorld.CallHelloWorld Return "(" + DateTime.Now.Millisecond.ToString() + ") HELLO WORLD 20100727_302pm"
End Function
End Class End Namespace
MYHELLOWORLD.SVC
(NAMESPACE for PROPER WSDL locations do not apply to this)
<%@ ServiceHost Language="VB" Debug="true" Service="WebApplication.myHelloWorld" CodeBehind="~/App_Code/myHelloWorld.vb" %>
DEFAULT.HTM (NOTICE THE NO-CACHING I AM USING FOR HTM FILE..SO THAT I CAN BETTER TROUBLESHOOT FASTER)
<head>
<meta http-equiv="Expires" content="Tue, 01 Jan 2000 12:12:12 GMT" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DOUG LUBEY WCF Display Shell TEST Version 2010-07-27</title>
<style type="text/css">
.loading
{
background-color: Aqua; }
.success
{
background-color: Green; }
.error
{
background-color: Yellow; }
</style> </head>
<script src="scripts/jquery-1.3.2.js" type="text/javascript"></script> <script src="scripts/json2.js" type="text/javascript"></script>
<script type="text/javascript">
var globalDjlScormWebServiceUrl = 'myHelloWorld.svc/webHttpBinding/';
$(document).ready(function () { djlHelloWorldInitiate();
});
function djlHelloWorldInitiate() { $.ajax({
type: "POST", //GET or POST or PUT or DELETE verb
url: globalDjlScormWebServiceUrl + "CallHelloWorld", //*****works with factory on the svc file //important to ensure the single and double quotes are correct
data: "", //newCourseStart, //'{"reqStudent": "' + locJavaStudents + '"}', //jsonText, //
contentType: "application/json; charset=utf-8", // content type sent to server
dataType: "json", ///"json", //Expected data format from server
//processdata : varProcessData, //True or False
success: djlHelloWorldSuccess,
error: djlHelloWorldFailure
});
}
function djlHelloWorldSuccess(data, status) { alert("helloWorld SUCCESS -150PM(POST):" + data.d); }
function djlHelloWorldFailure(request, status, error) { alert("helloWorld FAILED error is -150PM(POST):" + request.statusText ); }
FOR MORE ELABORATE JQUERY WHICH ACTUALLY USES JSON NOTATION AND SYNTAX
(SEE THE HYPERLINK TO THE XPS DOCUMENT TOWARDS THE TOP)
TO NOTE: i TRIED TO USE THE WIZARD BUT IT WAS A USELESS TOOL. (wcf SERVICE CONFIGURATION EDITOR TOOL SUCKS)
Search:
finally accomplished web services with out using ASMX files and stated using SVC files completely
wcf Metadata publishing for this service is currently disabled. multiple bindings 2010
wcf configuration bindings wizard
wcf configuration mulitple bindings wizard 2010
wcf configuration mulitple bindings wizard visual studio 2010
how to use wcf service configuration editor
example web.config file wcf with multiple bindings
wcf web.config file to support basicHttpBing and webHttpBinding
wcf mulitple bindings
jquery wcf services hello world
behaviorConfiguration Metadata publishing for this service is currently disabled
web.config behavior "Metadata publishing for this service is currently disabled"
OTHER ERRORS I RECEIVED THROUGH THE PROCESS:
Service 'myHelloWorld' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.
IIS specified authentication schemes 'IntegratedWindowsAuthentication, Anonymous', but the binding only supports specification of exactly one authentication scheme. Valid authentication schemes are Digest, Negotiate, NTLM, Basic, or Anonymous. Change the IIS settings so that only a single authentication scheme is used.
This collection already contains an address with scheme http. There can be at most one address per scheme in this collection. If your service is being hosted in IIS you can fix the problem by setting 'system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled' to true or specifying 'system.serviceModel/serviceHostingEnvironment/baseAddressPrefixFilters'.
Parameter name: item
The type 'myHelloWorld', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
When 'system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled' is set to true in configuration, the endpoints are required to specify a relative address. If you are specifying a relative listen URI on the endpoint, then the address can be absolute. To fix this problem, specify a relative uri for endpoint 'http://www.safetylca.org/DOUG2/WebServices4/myHelloWorld'.
A binding instance has already been associated to listen URI 'http://safetylca.org/DOUG2/WebServices4/myHelloWorld.svc'. If two endpoints want to share the same ListenUri, they must also share the same binding object instance. The two conflicting endpoints were either specified in AddServiceEndpoint() calls, in a config file, or a combination of AddServiceEndpoint() and config.
The body style 'Wrapped' is not supported by 'WebScriptEnablingBehavior'. Change the body style to be 'WrappedRequest'.
The type 'myHelloWorld', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
Operation 'getTrainingNumbersWithTwoParams' of contract 'IService' specifies multiple request body parameters to be serialized without any wrapper elements. At most one body parameter can be serialized without wrapper elements. Either remove the extra body parameters or set the BodyStyle property on the WebGetAttribute/WebInvokeAttribute to Wrapped.
key terms
flex4 (flash builder 4) jquery json wcf 4.0 webconfig how to setup communication (visual studio 2010 / .net 4.0)
WCF4 WEBCONFIG MUTLIPLE BINDINGS
windows communication foundation configuratino file settings
2010-07-27