问题
I am trying to develop a webservice
. In my application I need to connect to my webservice
without any referencing, so I use this code:
static void Main(string[] args)
{
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress("http://confdemo.spadsystem.com/WcfServiceLibrary1.Service1.svc");
ChannelFactory<IService1> factory = new ChannelFactory<IService1>(binding, address);
IService1 channel = factory.CreateChannel();
Console.WriteLine(channel.GetCategoryName(1));
Console.ReadLine();
}
But in this line channel.GetCategoryName(1)
I get this error :
There was no endpoint listening at http://confdemo.spadsystem.com/WcfServiceLibrary1.Service1.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
Here is my service webconfig
:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
</serviceHostingEnvironment>
<services>
<service name="WcfServiceLibrary1.Service1">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="confdemo.spadsystem.com/WcfServiceLibrary1.Service1.svc" binding="basicHttpBinding" contract="WcfServiceLibrary1.IService1">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
note:when I add the reference it works, it doesn't work when I don't add that to reference .
The error stacktrace:
System.ServiceModel.EndpointNotFoundException was unhandled by user code
HResult=-2146233087
Message=There was no endpoint listening at http://confdemo.spadsystem.com/WcfServiceLibrary1.Service1.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
Source=mscorlib
StackTrace:
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at WcfServiceLibrary1.IService1.GetCategoryName(Int32 productID)
at WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in c:\Users\ehsan\Documents\Visual Studio 2012\Projects\WcfService1\WebApplication1\WebForm1.aspx.cs:line 20
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException: System.Net.WebException
HResult=-2146233079
Message=The remote server returned an error: (404) Not Found.
Source=System
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
InnerException
回答1:
You said it worked when you added references. So my guess is that you have an issue in your endpoint.
According to your code you are expecting the endpoint to be http://confdemo.spadsystem.com/WcfServiceLibrary1.Service1.svc
. But your actual endpoint is http://confdemo.spadsystem.com/WcfServiceLibrary1.Service1.svc/confdemo.spadsystem.com/WcfServiceLibrary1.Service1.svc
.
In your wsdl it shows the url as
<wsdl:service name="Service1">
<wsdl:port name="BasicHttpBinding_IService1" binding="tns:BasicHttpBinding_IService1">
<soap:address location="http://confdemo.spadsystem.com
/WcfServiceLibrary1.Service1.svc/confdemo.spadsystem.com/WcfServiceLibrary1.Service1.svc"/>
</wsdl:port>
</wsdl:service>
I think this part this your web.config is not correct.
<endpoint address="confdemo.spadsystem.com/WcfServiceLibrary1.Service1.svc" binding="basicHttpBinding" contract="WcfServiceLibrary1.IService1">
来源:https://stackoverflow.com/questions/35169169/there-was-no-endpoint-listening-at-http-that-could-accept-the-message-in-wcf