Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 22nd, 2013, 09:02 PM
Registered User
Points: 32, Level: 1
Points: 32, Level: 1 Points: 32, Level: 1 Points: 32, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2013
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default NewService not working

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 &lt;xxxxxxxxxx.net &gt;">
<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>

Last edited by jcdavis57; September 23rd, 2013 at 05:43 PM..
Reply With Quote
  #2 (permalink)  
Old September 23rd, 2013, 04:12 AM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

This all looks fine to me except for one thing. There's a space in the behaviorConfiguration. This:

Code:
<endpoint address="" behaviorConfiguration="NameServiceAspNetAjaxBehavi  or"
          binding="webHttpBinding" contract="NameService" />
should be this:
Code:
<endpoint address="" behaviorConfiguration="NameServiceAspNetAjaxBehavior"
          binding="webHttpBinding" contract="NameService" />
However, I am not sure if that's the issue; this forum tends to add spaces to code at random, so this may just be a forum code issue.

Let me know if this does fix the issue. If not, we'll need to dig a little deeper.

BTW: you may want to edit your old post and get rid of the e-mail details.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old September 23rd, 2013, 05:45 PM
Registered User
Points: 32, Level: 1
Points: 32, Level: 1 Points: 32, Level: 1 Points: 32, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2013
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,

This must of been a forum issue because there is no space between the i and o.

Thanks for telling me about the email addresses. I have removed them.
Reply With Quote
  #4 (permalink)  
Old September 23rd, 2013, 05:50 PM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

In that case, I don't know what's going on. Your code works fine for me.

Have you tried debugging the client side code (Chapter 18 has more details) to see id it's a client side issue that raises a JavaScript error? Also, see if the issue reproduces in a different browser.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #5 (permalink)  
Old September 23rd, 2013, 06:45 PM
Registered User
Points: 32, Level: 1
Points: 32, Level: 1 Points: 32, Level: 1 Points: 32, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2013
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,

I tried running it using IE and I get a javascript error that says NameService is undefined. This occurs at line 20 of WebServices.aspx.
Reply With Quote
  #6 (permalink)  
Old September 23rd, 2013, 07:07 PM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Did you create the .svc file in the WebServices folder and did the .svc.cs file end up in the App_Code folder? What happens if you right-click the svc file in the WebServices folder and choose View in Browser?

Also, try Build | Rebuild website to force VS to recompile the site. Then look at the Errors List. Are there any errors?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #7 (permalink)  
Old September 24th, 2013, 07:03 PM
Registered User
Points: 32, Level: 1
Points: 32, Level: 1 Points: 32, Level: 1 Points: 32, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2013
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,

All code is in the correct folder and when I do rebuild there are no errors.

When I launch the svc file in the browser (both Firefox and IE) I get the following:
This is a Windows© Communication Foundation service.

Metadata publishing for this service is currently disabled.

If you have access to the service, you can enable metadata publishing by completing the following steps to modify your web or application configuration file:
When I go thru the steps they suggest I get the following exception:

The contract name 'IMetadataExchange' could not be found in the list of contracts implemented by the service NameService. Add a ServiceMetadataBehavior to the configuration file or to the ServiceHost directly to enable support for this contract.

Here is my web.config file (services portion only):

<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="NameServiceAspNetAjaxBehaviors" >
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
<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" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
</system.serviceModel>

Thanks,
John
Reply With Quote
  #8 (permalink)  
Old September 25th, 2013, 03:38 AM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi John,

The message "Metadata publishing for this service is currently disabled." is expected (see page 371, step 5). You don't need the meta data for the service to function correctly.

I checked and checked your code again and I can't see anything wrong. It works when I copy it in my Planet Wrox prooject. There could be something in other pages (the Master Page maybe) that you haven't posted here, but it's hard to tell.

Can you send me a zipped copy of the site so I can take a look? You find my e-mail address in the beginning of the book.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #9 (permalink)  
Old September 25th, 2013, 11:50 AM
Registered User
Points: 32, Level: 1
Points: 32, Level: 1 Points: 32, Level: 1 Points: 32, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2013
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, I will send you a zip of my solution.
Reply With Quote
  #10 (permalink)  
Old September 25th, 2013, 12:08 PM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi John,

Your web services folder is called WebSevices without an r. Rename it to WebServices and it should work.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"If or" not working crabjoe Classic ASP Basics 3 March 12th, 2008 06:03 PM
window.opener working .... not working alyeng2000 Javascript How-To 5 January 5th, 2007 08:05 AM
Web.Config..Working or Not Working peace95 ASP.NET 1.0 and 1.1 Basics 1 September 18th, 2006 06:53 AM
Local COM working , but not working at Web Serv nagen111 .NET Web Services 3 February 19th, 2005 04:22 AM
Get Working Copy... not working Enkiel Classic ASP Basics 0 April 21st, 2004 01:41 PM



All times are GMT -4. The time now is 05:12 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.