I cant seem to get the NameService to work. Here is my code.
NameService.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Web.Services;
using System.Text;
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class NameService
{
// To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json)
// To create an operation that returns XML,
// add [WebGet(ResponseFormat=WebMessageFormat.Xml)],
// and include the following line in the operation body:
// WebOperationContext.Current.OutgoingResponse.Conte ntType = "text/xml";
[OperationContract]
public string HelloWorld(string name)
{
// Add your operation implementation here
return string.Format ("Hope you are having a good day, {0}", name);
}
// Add more operations here and mark them with [OperationContract]
}
WebServices.aspx
<%@ Page Title="Web Services Demo" Language="C#" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="true" CodeFile="WebServices.aspx.cs" Inherits="Demos_WebServices" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
<Services>
<asp:ServiceReference Path="~/WebServices/NameService.svc" />
</Services>
</asp:ScriptManagerProxy>
<input id="YourName" type="text" />
<input id="SayHello" type="button" value="Say Hello" onclick="helloWorld()"/>
<script type="text/javascript">
function helloWorld()
{
var yourname = document.getElementById('YourName').value;
alert("my name: " + yourname);
NameService.HelloWorld(yourname, helloWorldCallback);
alert(yourname);
}
function helloWorldCallback(result)
{
alert(result);
}
function helloWorldPageMethod()
{
var yourname = document.getElementById('YourName').value;
alert(yourname);
PageMethods.HelloWorld(yourname, helloWorldCallback);
}
function helloWorldErrorCallback(error)
{
alert("here");
alert(error.get_Message);
}
</script>
<br />
<input id="SayHelloPageMethod" type="button" value="Say Hello with a Page Method" onclick="helloWorldPageMethod()" />
</asp:Content>
WebServices.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Demos_WebServices : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string HelloWorld(string name)
{
return string.Format("Hello {0}", name);
}
}
Web.config
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<appSettings>
<add key="ValidationSetting:UnobtrusiveValidationMode" value="None"/>
</appSettings>
<system.web>
<!--<pages theme="DarkGrey" styleSheetTheme="DarkGrey"/>-->
<pages theme="Monochrome" >
<controls>
<add tagPrefix="Wrox" tagName="Banner" src="~/Controls/Banner.ascx"/>
</controls>
</pages>
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="xxxxxxxxx <xxxxxxxxxx.net >">
<network enableSsl="true" host="smtp.att.yahoo.com" userName="xxxxxxxxxx.net" defaultCredentials="false" password="Dasher1d" port="587" />
</smtp>
</mailSettings>
</system.net>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="NameServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="NameService">
<endpoint address="" behaviorConfiguration="NameServiceAspNetAjaxBehavi or"
binding="webHttpBinding" contract="NameService" />
</service>
</services>
</system.serviceModel>
</configuration>