cheatcountry

I'm trying to create a web service that will read stock info from websites but I am getting many errors when trying to add the web service as a reference to my project. My code is below. I am getting an error that says "

Server Error in '/' Application.


Re: ASMX Web Services and XML Serialization many problems creating web service

John Saunders

You need to build the service before you can add a reference to it. The service also needs to be running.






Re: ASMX Web Services and XML Serialization many problems creating web service

cheatcountry

I have tried to build the web service and I get this error:

Could not create type 'RealTimeQuotes.StockServices'




Re: ASMX Web Services and XML Serialization many problems creating web service

John Saunders

Forget about the client for the moment. Please post the exact error messages you receive when you build the web service.






Re: ASMX Web Services and XML Serialization many problems creating web service

cheatcountry

John Saunders wrote:

Forget about the client for the moment. Please post the exact error messages you receive when you build the web service.



That is what I said, that is the exact error that I got when trying to build the web service...




Re: ASMX Web Services and XML Serialization many problems creating web service

John Saunders

Are you saying that when you right-click the web service project and use the command "Build", that it says "Cannot create web service" Does it say anything else at all Is this a compiler error message, or what I've nver seen a message like that when building a web service, only when trying to consume it.






Re: ASMX Web Services and XML Serialization many problems creating web service

cheatcountry

John Saunders wrote:

Are you saying that when you right-click the web service project and use the command "Build", that it says "Cannot create web service" Does it say anything else at all Is this a compiler error message, or what I've nver seen a message like that when building a web service, only when trying to consume it.



I right clicked and chose build and that error is what comes up. It doesn't say anything at all and I believe that it is a compiler error message. I haven't seen a message like this before either




Re: ASMX Web Services and XML Serialization many problems creating web service

John Saunders

Can you post the contents of your Output window You may need to display the output window via View->Output. Clear the Output window before the build by right-clicking in it and choosing "Clear All". Then do the build, and post the output here.






Re: ASMX Web Services and XML Serialization many problems creating web service

cheatcountry

The build was successful finally after working on it for the last couple of hours. I fixed the problems but now when I try to reference the web service from my project it gives me this error:
1  There was an error downloading 'http://localhost/Services/Service.asmx'.
2 The request failed with the error message:
3 --
4 <html>
5 <head>
6 <title>Parser Error</title>
7 <style>
8 body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
9 p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
10 b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
11 H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
12 H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
13 pre {font-family:"Lucida Console";font-size: .9em}
14 .marker {font-weight: bold; color: black;text-decoration: none;}
15 .version {color: gray;}
16 .error {margin-bottom: 10px;}
17 .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
18 </style>
19 </head>
20
21 <body bgcolor="white">
22
23 <span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>
24
25 <h2> <i>Parser Error</i> </h2></span>
26
27 <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
28
29 <b> Description: </b>An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
30 <br><br>
31
32 <b> Parser Error Message: </b>Could not create type 'StockServices'.<br><br>
33
34 <b>Source Error:</b> <br><br>
35
36 <table width=100% bgcolor="#ffffcc">
37 <tr>
38 <td>
39 <code><pre>
40
41 <font color=red>Line 1: <%@ WebService Language="C#" CodeBehind="~/App_Code/Service.cs" Class="StockServices" %>
42 </font></pre></code>
43
44 </td>
45 </tr>
46 </table>
47
48 <br>
49
50 <b> Source File: </b> /Services/Service.asmx<b> Line: </b> 1
51 <br><br>
52
53 <hr width=100% size=1 color=silver>
54
55 <b>Version Information:</b> Microsoft .NET Framework Version:2.0.50727.1373; ASP.NET Version:2.0.50727.1373
56
57 </font>
58
59 </body>
60 </html>
61 <!--
62 [HttpParseException]: Could not create type 'StockServices'.
63 at System.Web.UI.SimpleWebHandlerParser.GetType(String typeName)
64 at System.Web.UI.SimpleWebHandlerParser.GetTypeToCache(Assembly builtAssembly)
65 at System.Web.Compilation.SimpleHandlerBuildProvider.GetGeneratedType(CompilerResults results)
66 at System.Web.Compilation.BuildProvider.CreateBuildResult(CompilerResults results)
67 at System.Web.Compilation.BuildProvider.GetBuildResult(CompilerResults results)
68 at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
69 at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
70 at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
71 at System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath)
72 at System.Web.UI.WebServiceParser.GetCompiledType(String inputFile, HttpContext context)
73 at System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath)
74 at System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
75 at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
76 -->

77 --.
78 Metadata contains a reference that cannot be resolved: 'http://localhost/Services/Service.asmx'.
79 The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '<html>
80 <head>
81 <title>Parser Error</title>
82 <style>
83 body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
84 p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
85 b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
86 H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
87 H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
88 pre {font-family:"Lucida Console";font-size: .9em}
89 .marker {font-weight: bold; color: black;text-decoration: none;}
90 .version {color: gray;}
91 .error {margin-bottom: 10px;}
92 .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
93 </style>
94 </head>
95
96 <body bgcolor="white">
97
98 <span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>
99
100 <h2> <i>Parser Error</i> </h2></span>
101
102 '.
103 The remote server returned an error: (500) Internal Server Error.
104 If the service is defined in the current solution, try building the solution and adding the service reference again.





Re: ASMX Web Services and XML Serialization many problems creating web service

rfreire

Hi,

Make sure that the Class attribute in the Web Service definition tag (<@# WebService ...) is the fully qualified type name of the service.

In your first post it is was RealTimeQuotes.StockServices but now it shows just StockServices.

Regards,

Rodrigo





Re: ASMX Web Services and XML Serialization many problems creating web service

cheatcountry

rfreire wrote:

Hi,

Make sure that the Class attribute in the Web Service definition tag (<@# WebService ...) is the fully qualified type name of the service.

In your first post it is was RealTimeQuotes.StockServices but now it shows just StockServices.

Regards,

Rodrigo



Well I will post what my new code is. My first post was changed because it didn't work and it now works with the new version but it can't be referenced without an error...

using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Services;
using RealTimeQuotes;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class StockServices : WebService
{
public StockServices()
{
}

[WebMethod]
public string GetQuote(string ticker)
{
string stockURL, page, retval;
try
{
stockURL = GetURL(ticker);
page = ScrapeUtility.GetPageContent(stockURL);
retval = ParsePage(page);
}
catch (ArgumentOutOfRangeException)
{
retval = "Invalid Ticker!";
}
catch (Exception)
{
retval = "Unknown Error";
}

return retval;
}

[WebMethod]
public DataSet GetQuotes(string tickers)
{
char[] splitter = { ' ' };
string[] _tickers = tickers.Trim().Split(splitter);
Int32 i, ticks;

ticks = _tickers.Length;

DataSet ds = new DataSet();
DataTable dt = new DataTable("StockData");
DataColumn dc;

dc = dt.Columns.Add("Ticker", System.Type.GetType("System.String"));
dc = dt.Columns.Add("Price", System.Type.GetType("System.String"));

for (i = 0; i < ticks; i++)
{
DataRow dr = dt.NewRow();
dr["Ticker"] = _tickersIdea.ToUpper();
dr["Price"] = GetQuote(_tickersIdea);
dt.Rows.Add(dr);
}

ds.Tables.Add(dt);
return ds;
}

private string GetURL(string ticker)
{
StringBuilder url = new StringBuilder();

url.Append("http://finance.yahoo.com/q/ecn s=");
url.Append(ticker);

return url.ToString();
}

private string ParsePage(string page)
{
Int32 i;

i = page.IndexOf("Last Trade:");
page = page.Substring(i);

i = page.IndexOf("<b>");
page = page.Substring(i);

i = page.IndexOf("</b>");
page = page.Substring(0, i);

page = Regex.Replace(page, "<b>", "");
return page;
}
}


<%@ WebService Language="C#" CodeBehind="~/App_Code/Service.cs" Class="StockServices" %>

This is my other page:

using System;
using System.IO;
using System.Net;
using System.Text;

namespace RealTimeQuotes
{
/// <summary>
/// Summary description for StockUtility.
/// </summary>
public class ScrapeUtility
{
public ScrapeUtility(){}

public static string GetPageContent(string url)
{
WebRequest wreq;
WebResponse wres;
StreamReader sr;
String content;

wreq = HttpWebRequest.Create(url);
wres = wreq.GetResponse();
sr = new StreamReader(wres.GetResponseStream());
content = sr.ReadToEnd();
sr.Close();

return content;
}

}
}




Re: ASMX Web Services and XML Serialization many problems creating web service

rfreire

Did you try to create a proxy for your service instead of using HttpWebRequest and HttpWebResponse





Re: ASMX Web Services and XML Serialization many problems creating web service

John Saunders

I don't see where you are referencing the web service.

Also, remember that I said that the service has to be running before you can reference it. What evidence do you have that the service is running

Try to access the service directly from a web browser. I bet you get the same "can't create type" error.






Re: ASMX Web Services and XML Serialization many problems creating web service

cheatcountry

Well the service works now. I had to change the web.config to asp.net 2.0 instead of 3.5