I've created a very very simply WCF calculator service following a book example.
namespace WcfService1
{
// NOTE: If you change the class name "Calculator" here, you must also update the reference to "Calculator" in Web.config.
public class Calculator : ICalculator
{
public int Add(int a, int b)
{
return (a + b);
}
public int Subtract(int a, int b)
{
return (a - b);
}
public int Multiply(int a, int b)
{
return (a * b);
}
public int Divide(int a, int b)
{
return (a / b);
}
}
}
When I go to the browser http://localhost/WcfService1/Calculator.svc I see see the service. When I click on
http://jediacademy/WcfService1/Calculator.svc?wsdl I'm able to see the contract with no problem.
There was an error downloading 'http://jediacademy/WcfService1/Calculator.svc?wsdl'.
The underlying connection was closed: An unexpected error occurred on a receive.
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
An existing connection was forcibly closed by the remote host
Metadata contains a reference that cannot be resolved: 'http://jediacademy/WcfService1/Calculator.svc?wsdl'.
An error occurred while receiving the HTTP response to http://jediacademy/WcfService1/Calculator.svc?wsdl. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the
server (possibly due to the service shutting down). See server logs for more details.
The underlying connection was closed: An unexpected error occurred on a receive.
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
An existing connection was forcibly closed by the remote host
If the service is defined in the current solution, try building the solution and adding the service reference again.
Two small things. One, you're using "Add Service Reference", right? Second, please don't use "?wsdl". Just reference the .svc.
you want me to use Add Web Reference option? I did that and I've removed the ?wsdl.
What it gives me is basically what I saw in the browser before, the contract itself and I get a different error msg:
The document at the url http://localhost/WcfService1/Calculator.svc was not recognized as a known document type.
The error message from each known type may help you fix the problem:
- Report from 'http://localhost/WcfService1/Calculator.svc' is 'The document format is not recognized (the content ty
also when I run it from command prompt I get this:
Error: Cannot obtain Metadata from http://jediacademy/WcfService1/Calculator.svc
?wsdl
If this is a Windows (R) Communication Foundation service to which you have acce
ss, please check that you have enabled metadata publishing at the specified addr
ess. For help enabling metadata publishing, please refer to the MSDN documentat
ion at http://go.microsoft.com/fwlink/?LinkId=65455.
Metadata contains a reference that cannot be resolved: 'http://jediacademy/W
cfService1/Calculator.svc?wsdl'.
An error occurred while receiving the HTTP response to http://jediacademy/Wc
fService1/Calculator.svc?wsdl. This could be due to the service endpoint binding
not using the HTTP protocol. This could also be due to an HTTP request context
being aborted by the server (possibly due to the service shutting down). See ser
ver logs for more details.
The underlying connection was closed: An unexpected error occurred on a rece
ive.
Unable to read data from the transport connection: An existing connection wa
s forcibly closed by the remote host.
An existing connection was forcibly closed by the remote host
HTTP GET Error
URI: http://jediacademy/WcfService1/Calculator.svc?wsdl
There was an error downloading 'http://jediacademy/WcfService1/Calculator.sv
c?wsdl'.
The underlying connection was closed: An unexpected error occurred on a rece
ive.
Unable to read data from the transport connection: An existing connection wa
s forcibly closed by the remote host.
An existing connection was forcibly closed by the remote host
No, I wanted you to use "Add Service Reference", but to only specify the URL of the .svc file without the "?wsdl".
ok I did that, I've entered http://localhost/WcfService1/Calculator.svc it took it.
However, the address reverted to http://localhost/WcfService1/Calculator.svc/mex. I click OK. Unlike the book said I did not see any proxies created outside the service name - which is called ServiceReference1.
I went to CodeBehind and I've added the below code:
protected void Page_Load(object sender, EventArgs e)
{
ServiceReference1.CalculatorClient someObject = new ServiceReference1.CalculatorClient();
int result;
result = someObject.Multiply(5, 7);
Response.Write(result);
someObject.Close();
}
but I got this error:
An existing connection was forcibly closed by the remote host
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
I think we are almost there, thanks so much for your help.
I have some success to report. I created a console based WCF service, and I was able to service reference it in ASP.NET application successfully. I got the video example from Pluralsight. I would try to write the same service now, but as WCF ASP.NET service
and host it in IIS. If this goes well, I will tackle on this current Calculator service using similar approach.
I got some break through, I think this is related to what is happening. I've stopped the service from running and refreshed my ASP.NET page, I got the same error that the connection was forcibly closed. Would that mean that the IIS is not in fact running
the application?
ok I've successfully tested the service hosted on IIS but it was using the wcftestclient utility. If I reference it from ASP.NET I get the An existing connection was forcibly closed by the remote host.
LastManStand...
Member
475 Points
252 Posts
Problems referencing a simple WCF service in ASP.NET
Feb 01, 2009 06:48 PM|LINK
I've created a very very simply WCF calculator service following a book example.
namespace WcfService1 { // NOTE: If you change the class name "Calculator" here, you must also update the reference to "Calculator" in Web.config. public class Calculator : ICalculator { public int Add(int a, int b) { return (a + b); } public int Subtract(int a, int b) { return (a - b); } public int Multiply(int a, int b) { return (a * b); } public int Divide(int a, int b) { return (a / b); } } }When I go to the browser http://localhost/WcfService1/Calculator.svc I see see the service. When I click on http://jediacademy/WcfService1/Calculator.svc?wsdl I'm able to see the contract with no problem.
Then I go to Visual Studio 2008, create a simple web application project, and when I reference the service URL: http://jediacademy/WcfService1/Calculator.svc?wsdl
I get lots of errors:
There was an error downloading 'http://jediacademy/WcfService1/Calculator.svc?wsdl'.
The underlying connection was closed: An unexpected error occurred on a receive.
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
An existing connection was forcibly closed by the remote host
Metadata contains a reference that cannot be resolved: 'http://jediacademy/WcfService1/Calculator.svc?wsdl'.
An error occurred while receiving the HTTP response to http://jediacademy/WcfService1/Calculator.svc?wsdl. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
The underlying connection was closed: An unexpected error occurred on a receive.
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
An existing connection was forcibly closed by the remote host
If the service is defined in the current solution, try building the solution and adding the service reference again.
I don't know what to do help.
johnwsaunder...
Star
11262 Points
1981 Posts
Re: Problems referencing a simple WCF service in ASP.NET
Feb 01, 2009 09:13 PM|LINK
Two small things. One, you're using "Add Service Reference", right? Second, please don't use "?wsdl". Just reference the .svc.
LastManStand...
Member
475 Points
252 Posts
Re: Problems referencing a simple WCF service in ASP.NET
Feb 01, 2009 10:09 PM|LINK
you want me to use Add Web Reference option? I did that and I've removed the ?wsdl.
What it gives me is basically what I saw in the browser before, the contract itself and I get a different error msg:
The document at the url http://localhost/WcfService1/Calculator.svc was not recognized as a known document type.
The error message from each known type may help you fix the problem:
- Report from 'http://localhost/WcfService1/Calculator.svc' is 'The document format is not recognized (the content ty
also when I run it from command prompt I get this:
Error: Cannot obtain Metadata from http://jediacademy/WcfService1/Calculator.svc
?wsdl
If this is a Windows (R) Communication Foundation service to which you have acce
ss, please check that you have enabled metadata publishing at the specified addr
ess. For help enabling metadata publishing, please refer to the MSDN documentat
ion at http://go.microsoft.com/fwlink/?LinkId=65455.
WS-Metadata Exchange Error
URI: http://jediacademy/WcfService1/Calculator.svc?wsdl
Metadata contains a reference that cannot be resolved: 'http://jediacademy/W
cfService1/Calculator.svc?wsdl'.
An error occurred while receiving the HTTP response to http://jediacademy/Wc
fService1/Calculator.svc?wsdl. This could be due to the service endpoint binding
not using the HTTP protocol. This could also be due to an HTTP request context
being aborted by the server (possibly due to the service shutting down). See ser
ver logs for more details.
The underlying connection was closed: An unexpected error occurred on a rece
ive.
Unable to read data from the transport connection: An existing connection wa
s forcibly closed by the remote host.
An existing connection was forcibly closed by the remote host
HTTP GET Error
URI: http://jediacademy/WcfService1/Calculator.svc?wsdl
There was an error downloading 'http://jediacademy/WcfService1/Calculator.sv
c?wsdl'.
The underlying connection was closed: An unexpected error occurred on a rece
ive.
Unable to read data from the transport connection: An existing connection wa
s forcibly closed by the remote host.
An existing connection was forcibly closed by the remote host
If you would like more help, type "svcutil /?"
johnwsaunder...
Star
11262 Points
1981 Posts
Re: Problems referencing a simple WCF service in ASP.NET
Feb 01, 2009 10:30 PM|LINK
No, I wanted you to use "Add Service Reference", but to only specify the URL of the .svc file without the "?wsdl".
LastManStand...
Member
475 Points
252 Posts
Re: Problems referencing a simple WCF service in ASP.NET
Feb 02, 2009 12:10 AM|LINK
ok I did that, I've entered http://localhost/WcfService1/Calculator.svc it took it.
However, the address reverted to http://localhost/WcfService1/Calculator.svc/mex. I click OK. Unlike the book said I did not see any proxies created outside the service name - which is called ServiceReference1.
I went to CodeBehind and I've added the below code:
protected void Page_Load(object sender, EventArgs e)
{
ServiceReference1.CalculatorClient someObject = new ServiceReference1.CalculatorClient();
int result;
result = someObject.Multiply(5, 7);
Response.Write(result);
someObject.Close();
}
but I got this error:
An existing connection was forcibly closed by the remote hostDescription: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
I think we are almost there, thanks so much for your help.
johnwsaunder...
Star
11262 Points
1981 Posts
Re: Problems referencing a simple WCF service in ASP.NET
Feb 02, 2009 12:52 AM|LINK
Let's try another simplifying step. Change the binding from wsHttpBinding to basicHttpBinding, and see what happens.
LastManStand...
Member
475 Points
252 Posts
Re: Problems referencing a simple WCF service in ASP.NET
Feb 02, 2009 02:11 AM|LINK
that did not work either. I'm so desperate that Hello World will do it for me now.
LastManStand...
Member
475 Points
252 Posts
Re: Problems referencing a simple WCF service in ASP.NET
Feb 02, 2009 03:34 AM|LINK
I have some success to report. I created a console based WCF service, and I was able to service reference it in ASP.NET application successfully. I got the video example from Pluralsight. I would try to write the same service now, but as WCF ASP.NET service and host it in IIS. If this goes well, I will tackle on this current Calculator service using similar approach.
LastManStand...
Member
475 Points
252 Posts
Re: Problems referencing a simple WCF service in ASP.NET
Feb 02, 2009 03:40 AM|LINK
I got some break through, I think this is related to what is happening. I've stopped the service from running and refreshed my ASP.NET page, I got the same error that the connection was forcibly closed. Would that mean that the IIS is not in fact running the application?
LastManStand...
Member
475 Points
252 Posts
Re: Problems referencing a simple WCF service in ASP.NET
Feb 02, 2009 05:14 AM|LINK
ok I've successfully tested the service hosted on IIS but it was using the wcftestclient utility. If I reference it from ASP.NET I get the An existing connection was forcibly closed by the remote host.
so perhaphs the problem is in the IIS?